forked from omriharel/deej
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray.go
86 lines (65 loc) · 2.09 KB
/
tray.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
package deej
import (
"github.com/getlantern/systray"
"github.com/omriharel/deej/icon"
"github.com/omriharel/deej/util"
)
func (d *Deej) initializeTray(onDone func()) {
logger := d.logger.Named("tray")
onReady := func() {
logger.Debug("Tray instance ready")
systray.SetTemplateIcon(icon.DeejLogo, icon.DeejLogo)
systray.SetTitle("deej")
systray.SetTooltip("deej")
editConfig := systray.AddMenuItem("Edit configuration", "Open config file with notepad")
editConfig.SetIcon(icon.EditConfig)
refreshSessions := systray.AddMenuItem("Re-scan audio sessions", "Manually refresh audio sessions if something's stuck")
refreshSessions.SetIcon(icon.RefreshSessions)
if d.version != "" {
systray.AddSeparator()
versionInfo := systray.AddMenuItem(d.version, "")
versionInfo.Disable()
}
systray.AddSeparator()
quit := systray.AddMenuItem("Quit", "Stop deej and quit")
// wait on things to happen
go func() {
for {
select {
// quit
case <-quit.ClickedCh:
logger.Info("Quit menu item clicked, stopping")
d.signalStop()
// edit config
case <-editConfig.ClickedCh:
logger.Info("Edit config menu item clicked, opening config for editing")
editor := "notepad.exe"
if util.Linux() {
editor = "gedit"
}
if err := util.OpenExternal(logger, editor, userConfigFilepath); err != nil {
logger.Warnw("Failed to open config file for editing", "error", err)
}
// refresh sessions
case <-refreshSessions.ClickedCh:
logger.Info("Refresh sessions menu item clicked, triggering session map refresh")
// performance: the reason that forcing a refresh here is okay is that users can't spam the
// right-click -> select-this-option sequence at a rate that's meaningful to performance
d.sessions.refreshSessions(true)
}
}
}()
// actually start the main runtime
onDone()
}
onExit := func() {
logger.Debug("Tray exited")
}
// start the tray icon
logger.Debug("Running in tray")
systray.Run(onReady, onExit)
}
func (d *Deej) stopTray() {
d.logger.Debug("Quitting tray")
systray.Quit()
}