-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
132 lines (130 loc) · 4.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"awesome-hosts/manager"
"awesome-hosts/parameters"
"flag"
"github.com/asticode/go-astilectron"
"github.com/asticode/go-astilectron-bootstrap"
"github.com/asticode/go-astilog"
"github.com/pkg/errors"
)
func main() {
//init manager instance
m = manager.New(manager.GetUserHome() + "/.awesohosts").Init()
handler := new(Handler)
handler.Parameters = parameters.New()
// Init
flag.Parse()
astilog.FlagInit()
// Run bootstrap
astilog.Debugf("Running app built at %s", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: AppName,
AppIconDarwinPath: "resources/icon.icns",
AppIconDefaultPath: "resources/icon.png",
},
Debug: *debug,
RestoreAssets: RestoreAssets,
OnWait: func(_ *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
m.Window = ws[0]
return nil
},
//MenuOptions: []*astilectron.MenuItemOptions{{
// Label: astilectron.PtrStr("File"),
// SubMenu: []*astilectron.MenuItemOptions{
// {
// Label: astilectron.PtrStr("About"),
// OnClick: func(e astilectron.Event) (deleteListener bool) {
// //if err := bootstrap.SendMessage(w, "NewGroup", htmlAbout, func(m *bootstrap.MessageIn) {
// // // Unmarshal payload
// // var s string
// // if err := json.Unmarshal(m.Payload, &s); err != nil {
// // astilog.Error(errors.Wrap(err, "unmarshaling payload failed"))
// // return
// // }
// // astilog.Infof("About modal has been displayed and payload is %s!", s)
// //}); err != nil {
// // astilog.Error(errors.Wrap(err, "sending about event failed"))
// //}
// return
// },
// },
// {
// Label: astilectron.PtrStr("New"),
// OnClick: func(e astilectron.Event) (deleteListener bool) {
// //if err := bootstrap.SendMessage(w, "NewGroup", htmlAbout, func(m *bootstrap.MessageIn) {
// // // Unmarshal payload
// // var s string
// // if err := json.Unmarshal(m.Payload, &s); err != nil {
// // astilog.Error(errors.Wrap(err, "unmarshaling payload failed"))
// // return
// // }
// // astilog.Infof("About modal has been displayed and payload is %s!", s)
// //}); err != nil {
// // astilog.Error(errors.Wrap(err, "sending about event failed"))
// //}
// return
// },
// },
// {Role: astilectron.MenuItemRoleReload},
// {Role: astilectron.MenuItemRoleToggleFullScreen},
// },
//},{
// Label: astilectron.PtrStr("File"),
// SubMenu: []*astilectron.MenuItemOptions{
// {
// Label: astilectron.PtrStr("About"),
// OnClick: func(e astilectron.Event) (deleteListener bool) {
// //if err := bootstrap.SendMessage(w, "NewGroup", htmlAbout, func(m *bootstrap.MessageIn) {
// // // Unmarshal payload
// // var s string
// // if err := json.Unmarshal(m.Payload, &s); err != nil {
// // astilog.Error(errors.Wrap(err, "unmarshaling payload failed"))
// // return
// // }
// // astilog.Infof("About modal has been displayed and payload is %s!", s)
// //}); err != nil {
// // astilog.Error(errors.Wrap(err, "sending about event failed"))
// //}
// return
// },
// },
// {
// Label: astilectron.PtrStr("New"),
// OnClick: func(e astilectron.Event) (deleteListener bool) {
// //if err := bootstrap.SendMessage(w, "NewGroup", htmlAbout, func(m *bootstrap.MessageIn) {
// // // Unmarshal payload
// // var s string
// // if err := json.Unmarshal(m.Payload, &s); err != nil {
// // astilog.Error(errors.Wrap(err, "unmarshaling payload failed"))
// // return
// // }
// // astilog.Infof("About modal has been displayed and payload is %s!", s)
// //}); err != nil {
// // astilog.Error(errors.Wrap(err, "sending about event failed"))
// //}
// return
// },
// },
// {Role: astilectron.MenuItemRoleClose},
// },
//}},
Windows: []*bootstrap.Window{{
Homepage: "index.html",
MessageHandler: handler.handleMessages,
Options: &astilectron.WindowOptions{
BackgroundColor: astilectron.PtrStr("#2d3e50"),
Center: astilectron.PtrBool(true),
Height: astilectron.PtrInt(650),
Width: astilectron.PtrInt(950),
MinHeight: astilectron.PtrInt(650),
MinWidth: astilectron.PtrInt(950),
},
}},
}); err != nil {
astilog.Fatal(errors.Wrap(err, "running bootstrap failed"))
}
}