-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplatform_darwin.go
86 lines (73 loc) · 1.83 KB
/
platform_darwin.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
//go:build darwin
package main
import (
"bytes"
"fmt"
"net/http"
"os"
"os/exec"
"github.com/getlantern/systray"
)
func openBrowser(url string) error {
return exec.Command("open", url).Start()
}
func onReadySysTray() {
iconData, _ := Asset("../icon.ico")
systray.SetIcon(iconData)
//systray.SetTitle("QVNote")
mBrowser := systray.AddMenuItem("Open browser", "open default browser with this app page")
mRelod := systray.AddMenuItem("Reload notes", "may be slow")
systray.AddSeparator()
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
for {
select {
case <-mBrowser.ClickedCh:
openBrowser("http://localhost:" + configGlobal.cmdPort + "/")
case <-mRelod.ClickedCh:
url := "http://localhost:" + configGlobal.cmdPort + "/api/refresh_data.json"
var jsonStr = []byte(`{"action":"reload"}`)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
resp.Body.Close()
case <-mQuit.ClickedCh:
systray.Quit()
fmt.Println("Good buy!")
os.Exit(0)
}
}
}
func runSystray() {
systray.Run(onReadySysTray, onExitSysTray)
}
func onExitSysTray() {
// clean up here
client := http.Client{}
client.Get("http://localhost:" + configGlobal.cmdPort + "/api/exit")
os.Exit(0)
}
func initConsole() {}
func initPlatformSpecific() error {
if configGlobal.cmdServerMode {
return nil
}
if configGlobal.appStartingMode != "independent" {
cwd, err := os.Getwd()
if err != nil {
return err
}
systrayProcess = exec.Command(os.Args[0], "--systray", configGlobal.cmdPort)
systrayProcess.Dir = cwd
err = systrayProcess.Start()
if err != nil {
return err
}
//systrayProcess.Process.Kill()
//systrayProcess.Process.Release()
}
return nil
}