forked from getlantern/systray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systray_example.go
76 lines (63 loc) · 1.64 KB
/
systray_example.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 (
"fmt"
"path/filepath"
"github.com/anjannath/systray"
"github.com/anjannath/systray/example/icon"
)
var (
menuTitles = []string{"minishift", "kuberenets", "kubedash", "kvirt"}
submenus = make(map[string]*systray.MenuItem)
submenusToMenuItems = make(map[string]MenuAction)
)
func main() {
systray.Run(onReady, onExit)
}
type MenuAction struct {
start *systray.MenuItem
stop *systray.MenuItem
}
func onReady() {
bp, _ := filepath.Abs("running.bmp")
systray.SetIcon(icon.Data)
exit := systray.AddMenuItem("Exit", "", 0)
m1 := systray.AddSubMenu("Test..")
sm2 := m1.AddSubMenuItem("Second Item", "", 0)
sm2.AddBitmapPath(bp)
exit.AddBitmapPath(bp)
systray.AddSeparator()
for _, menuTitle := range menuTitles {
submenu := systray.AddSubMenu(menuTitle)
startMenu := submenu.AddSubMenuItem("Start", "", 0)
stopMenu := submenu.AddSubMenuItem("Stop", "", 0)
submenu.AddBitmap(icon.Data)
submenus[menuTitle] = submenu
submenusToMenuItems[menuTitle] = MenuAction{start: startMenu, stop: stopMenu}
}
go func() {
<-exit.OnClickCh()
systray.Quit()
}()
iconStart, _ := filepath.Abs("running.bmp")
iconStop, _ := filepath.Abs("stopped.bmp")
for k, v := range submenusToMenuItems {
fmt.Println(k)
go func(iconpath, submenu string, v MenuAction) {
for {
<-v.start.OnClickCh()
v.start.Disable()
submenus[submenu].AddBitmapPath(iconpath)
}
}(iconStart, k, v)
go func(iconpath, submenu string, v MenuAction) {
for {
<-v.stop.OnClickCh()
v.stop.Disable()
v.start.Enable()
submenus[submenu].AddBitmapPath(iconpath)
}
}(iconStop, k, v)
}
}
func onExit() {
}