-
Notifications
You must be signed in to change notification settings - Fork 1
/
systray.go
116 lines (101 loc) · 2.22 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
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
package main
import (
"log"
"os/exec"
"github.com/lxn/walk"
"github.com/lxn/win"
)
func SetSystrayContextMenu() {
type menuItem struct {
separator bool
text string
fn func()
}
contexts := tabMan.FindAll(allTabsFinder)
menu := make([]menuItem, len(contexts))
i := len(contexts) - 1
for _, ctx := range contexts {
t := ctx.tab
tabTitle := t.Title()
_, split := t.(*tabServer)
// NOTE(tso): have to do this and the curried function because of reasons
idx := t.Index()
if idx == -1 || idx >= len(menu) /* I don't understand either */ {
idx = i
i--
}
menu[idx] = menuItem{
separator: split,
text: tabTitle,
fn: func(t tab) func() {
return func() {
tabWidget.SetCurrentIndex(t.Index())
mainWindowHidden = false
win.ShowWindow(mw.Handle(), win.SW_NORMAL)
}
}(t),
}
}
menu = append(menu,
menuItem{
separator: true,
text: "Settings",
fn: settingsDialog,
},
menuItem{
text: "About",
fn: aboutDialog,
},
menuItem{
text: "Help",
fn: func() {
ctx := tabMan.Find(currentTabFinder)
if ctx == nil {
return
}
if t, ok := ctx.tab.(tabWithTextBuffer); ok {
ctx := &commandContext{tab: t}
helpCmd(ctx)
}
},
},
menuItem{
separator: true,
text: "Report Issue on GitHub",
fn: reportIssue,
},
menuItem{
separator: true,
text: "Quit",
fn: exit,
},
)
mw.Synchronize(func() {
systray.ContextMenu().Actions().Clear()
for _, item := range menu {
if item.separator {
systray.ContextMenu().Actions().Add(walk.NewSeparatorAction())
}
action := walk.NewAction()
action.SetText(item.text)
action.Triggered().Attach(item.fn)
systray.ContextMenu().Actions().Add(action)
}
})
}
func reportIssue() {
url := "https://github.com/dayvonjersen/chopsuey/issues/new"
cmd := exec.Command("cmd", "/c", "start", url)
if err := cmd.Run(); err != nil {
log.Println("cmd /c start", url, "returned error:\n", err)
}
}
func aboutDialog() {
walk.MsgBox(mw, "About", " chopsuey "+VERSION_STRING+`
github.com/dayvonjersen/chopsuey
`, walk.MsgBoxOK)
}
func settingsDialog() {
walk.MsgBox(mw, "Settings", "soon™", walk.MsgBoxOK)
}