-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
70 lines (58 loc) · 1.43 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
package main
import (
"github.com/getlantern/systray"
"github.com/psidex/EACS/config"
"github.com/psidex/EACS/icon"
"strings"
)
// Find takes a slice and looks for an element in it. If found it will return true, else false.
// https://golangcode.com/check-if-element-exists-in-slice/
func find(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Equalizer APO Config Switcher")
systray.SetTooltip("Equalizer APO Config Switcher")
configSlice := config.CreateConfigSlice()
currentConfigFileNames := config.ReadConfigFromMaster()
for _, configStruct := range configSlice {
configName := strings.Replace(configStruct.FileName, ".txt", "", 1)
btn := systray.AddMenuItem(configName, "Activate / Deactivate this config")
configStruct.MenuItem = btn
// If this config is already in the config master file
if find(currentConfigFileNames, configStruct.FileName) {
btn.Check()
}
go func() {
for {
<-btn.ClickedCh
if !btn.Checked() {
btn.Check()
} else {
btn.Uncheck()
}
config.WriteConfigToMaster(configSlice)
}
}()
}
systray.AddSeparator()
QuitBtn := systray.AddMenuItem("Quit", "Quit the whole app")
go func() {
for {
<-QuitBtn.ClickedCh
systray.Quit()
}
}()
}
func onExit() {
// No cleanup needed
}
func main() {
systray.Run(onReady, onExit)
}