-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tray.go
123 lines (110 loc) · 3.49 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
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
117
118
119
120
121
122
123
package main
import (
"fmt"
"os"
"runtime"
"time"
"github.com/getlantern/systray"
log "github.com/sirupsen/logrus"
"github.com/skratchdot/open-golang/open"
)
func (instanceManager *ActionPadInstanceManager) runInterface() {
systray.Run(instanceManager.onReady, instanceManager.onExit)
}
func (instanceManager *ActionPadInstanceManager) onReady() {
if runtime.GOOS == "windows" {
systray.SetIcon(WinIcon)
} else {
systray.SetIcon(UnixIcon)
}
systray.SetTooltip("ActionPad Server")
mTitle := systray.AddMenuItem("ActionPad Server "+CURRENT_VERSION+" (by Andrew Arpasi)", "ActionPad Server")
mStatus := systray.AddMenuItem("Status: ", "Status")
mTitle.Disable()
mStatus.Disable()
systray.AddSeparator()
mPairing := systray.AddMenuItem("Connect Devices (Enable Pairing)", "Connect Devices")
mShowInfo := systray.AddMenuItem("Show Server Information", "Show Server Information")
systray.AddSeparator()
// mSettings := systray.AddMenuItem("Change IP/Port", "Server Settings")
mConfig := systray.AddMenuItem("Edit Server Config File", "Edit Config File")
mUpdate := systray.AddMenuItem("Check For Server Update", "Check For Server Update")
systray.AddSeparator()
mRestart := systray.AddMenuItem("Restart", "Restart")
mQuit := systray.AddMenuItem("Quit", "Quit")
configLoad()
mStatus.SetTitle("Status: " + instanceManager.statusMessage)
mPairing.SetTitle(getPairingButtonMessage())
if GetBool("pairingEnabled") {
go func() {
time.Sleep(time.Second)
open.Start(qrPageURL())
}()
}
go func() {
for {
select {
case <-mPairing.ClickedCh:
setPairingEnabled(!GetBool("pairingEnabled"))
configLoad()
mPairing.SetTitle(getPairingButtonMessage())
if GetBool("pairingEnabled") {
open.Start(qrPageURL())
}
case <-mShowInfo.ClickedCh:
configLoad()
open.Start(qrPageURL())
case <-mQuit.ClickedCh:
instanceManager.onExit()
return
case <-mConfig.ClickedCh:
if runtime.GOOS == "darwin" {
open.RunWith(ConfigFileUsed(), "/System/Applications/TextEdit.app/Contents/MacOS/TextEdit")
} else if runtime.GOOS == "windows" {
open.RunWith(ConfigFileUsed(), "notepad.exe")
}
case <-mUpdate.ClickedCh:
open.Start("https://actionpad.co/update.html?version=" + CURRENT_VERSION)
//
// BUG:
//
// Restarting while pairing mode stops pairing mode from ever working again until actual force restart.
//
case <-mRestart.ClickedCh:
log.Println("Engine:", instanceManager.engine)
if instanceManager.engine != nil {
fmt.Print("Killing engine on PID ")
log.Println(instanceManager.engine.Pid)
instanceManager.engine.Kill()
instanceManager.spawnEngine()
mStatus.SetTitle("Status: " + instanceManager.statusMessage)
} else {
instanceManager.spawnEngine()
mStatus.SetTitle("Status: " + instanceManager.statusMessage)
}
go func() {
time.Sleep(time.Second)
configLoad()
log.Println("Should update status:", instanceManager.statusMessage)
mStatus.SetTitle("Status: " + instanceManager.statusMessage)
mPairing.SetTitle(getPairingButtonMessage())
}()
}
}
}()
}
func getPairingButtonMessage() string {
if GetBool("pairingEnabled") {
return "Done Connecting Devices (Disable Pairing)"
}
return "Connect Devices (Enable Pairing)"
}
func (instanceManager *ActionPadInstanceManager) onExit() {
// clean up here
if instanceManager.engine != nil {
fmt.Print("Killing engine on PID ")
log.Println(instanceManager.engine.Pid)
instanceManager.engine.Kill()
}
os.Exit(0)
}