-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSystray.go
76 lines (69 loc) · 1.45 KB
/
Systray.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
package main
import (
"log"
"os"
"path"
"github.com/getlantern/systray"
"github.com/skratchdot/open-golang/open"
)
var (
exePath string
mInfo, mEnable, mReload, mHelp, mQuit *systray.MenuItem
)
func main() {
var err error
exePath, err = os.Executable()
if err != nil {
log.Panic(err)
}
exePath = path.Dir(exePath)
systray.Run(onReady, onExit)
}
func onExit() {
enable(false)
}
func onReady() {
mInfo = systray.AddMenuItem(versionStr, authorStr)
mInfo.Disable()
systray.AddSeparator()
mEnable = systray.AddMenuItem("Pause", "Pause Gosture")
mReload = systray.AddMenuItem("Reload Config", "Reload configuraton file")
mHelp = systray.AddMenuItem("Help", "Open user manual")
systray.AddSeparator()
mQuit = systray.AddMenuItem("Quit", "Quit Gosture")
systray.SetIcon(iconON)
systray.SetTitle(versionStr)
systray.SetTooltip(authorStr)
go gosture()
for {
select {
case <-mInfo.ClickedCh:
case <-mEnable.ClickedCh:
enable(!ena)
onToggle()
case <-mReload.ClickedCh:
reload()
case <-mHelp.ClickedCh:
open.Run(path.Join(exePath, "Gosture_Help.htm"))
case <-mQuit.ClickedCh:
systray.Quit()
return
}
}
}
func onToggle() {
if ena {
systray.SetIcon(iconON)
mEnable.SetTitle("Pause")
mEnable.SetTooltip("Pause Gosture")
} else {
systray.SetIcon(iconOFF)
mEnable.SetTitle("Resume")
mEnable.SetTooltip("Resume Gosture")
}
if rdy {
mEnable.Enable()
} else {
mEnable.Disable()
}
}