-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
117 lines (108 loc) · 3.28 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
package main
import (
"github.com/asticode/go-astikit"
"github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
jww "github.com/spf13/jwalterweatherman"
"github.com/xx-labs/cmix-proxy-app/backend"
)
// Vars injected via ldflags by bundler
var (
AppName string
BuiltAt string
VersionAstilectron string
VersionElectron string
)
// Application Vars
var (
w *astilectron.Window
resources string
appdata string
)
func main() {
// Get backend config
config := backend.DefaultConfig(AppName)
// Setup logging
backend.SetupLogging(config.DataDir)
// New handler
handler := backend.NewHandler(config)
// Run bootstrap
jww.INFO.Printf("Running app built at %s\n", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: AppName,
AppIconDarwinPath: "resources/icon.icns",
AppIconDefaultPath: "resources/icon.png",
SingleInstance: true,
VersionAstilectron: VersionAstilectron,
VersionElectron: VersionElectron,
},
Logger: jww.DEBUG,
MenuOptions: []*astilectron.MenuItemOptions{{
Label: astikit.StrPtr("File"),
SubLabel: astikit.StrPtr("File"),
SubMenu: []*astilectron.MenuItemOptions{
{ // Add about menu item
Label: astikit.StrPtr("About"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
bootstrap.SendMessage(w, "about", nil)
return
},
},
{ // Add restore window menu item
Label: astikit.StrPtr("Reset App"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
// Create backend messages
msgDisconnect := bootstrap.MessageIn{
Name: "disconnect",
}
msgReset := bootstrap.MessageIn{
Name: "reset",
}
// Notify frontend that reset is happening
err := bootstrap.SendMessage(w, "resetting", nil)
if err != nil {
jww.DEBUG.Printf("[Bootstrap] Error sending resetting message to frontend: %s", err.Error())
}
// Disconnect and reset
_, err = handler.HandleMessages(w, msgDisconnect)
if err != nil {
jww.DEBUG.Printf("[Disconnect] Error message: %s", err.Error())
}
_, err = handler.HandleMessages(w, msgReset)
if err != nil {
jww.DEBUG.Printf("[Reset] Error message: %s", err.Error())
} else {
// Notify frontend that reset is complete
err = bootstrap.SendMessage(w, "reset", nil)
if err != nil {
jww.DEBUG.Printf("[Bootstrap] Error sending reset message to frontend: %s", err.Error())
}
}
return
},
},
{Role: astilectron.MenuItemRoleClose},
},
}},
OnWait: func(_ *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
w = ws[0]
return nil
},
RestoreAssets: RestoreAssets,
Windows: []*bootstrap.Window{{
Homepage: "index.html",
MessageHandler: handler.HandleMessages,
Options: &astilectron.WindowOptions{
BackgroundColor: astikit.StrPtr("#333"),
Center: astikit.BoolPtr(true),
Height: astikit.IntPtr(800),
Width: astikit.IntPtr(450),
},
}},
}); err != nil {
jww.FATAL.Printf("running bootstrap failed: %v", err)
}
}