Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
108 lines (92 loc) · 1.97 KB
/
Copy pathmain.go
File metadata and controls
108 lines (92 loc) · 1.97 KB
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
package main
import (
"context"
"flag"
"fmt"
"log"
"sync"
"github.com/getlantern/systray"
)
var (
wg sync.WaitGroup
Port int
Password string
Notify int
)
func setupTray(cancel context.CancelFunc) {
systray.SetIcon(IconData)
systray.SetTitle("EverCliping")
systray.SetTooltip("EverCliping")
isAutoRun, err := QueryAutoRun()
if err != nil {
log.Println("[Warn] Unable to query AutoRun status:", err)
}
mOpen := systray.AddMenuItem("连接指南 (Guide)", "Guide")
systray.AddSeparator()
mAutorun := systray.AddMenuItemCheckbox("开机自启 (Autorun)", "Autorun", isAutoRun)
mQuit := systray.AddMenuItem("退出 (Exit)", "Exit")
go func() {
for {
select {
case <-mOpen.ClickedCh:
OpenBrowser(fmt.Sprintf("http://localhost:%d", Port))
case <-mAutorun.ClickedCh:
if mAutorun.Checked() {
err := DisableAutoRun()
if err != nil {
log.Println("[Warn] Unable to disable AutoRun:", err)
continue
}
mAutorun.Uncheck()
} else {
err := EnableAutoRun()
if err != nil {
log.Println("[Warn] Unable to enable AutoRun:", err)
continue
}
mAutorun.Check()
}
case <-mQuit.ClickedCh:
cancel()
systray.Quit()
}
}
}()
}
func OnReady() {
ctx, cancel := context.WithCancel(context.Background())
ClipboardInit()
// TODO: mDNS support
// go func() {
// defer wg.Done()
// wg.Add(1)
// StartMDNSServer(ctx, Port)
// }()
go func() {
defer wg.Done()
wg.Add(1)
StartHTTPServer(ctx, Port)
}()
go func() {
defer wg.Done()
wg.Add(1)
WatchText(ctx)
}()
go func() {
defer wg.Done()
wg.Add(1)
WatchImage(ctx)
}()
setupTray(cancel)
}
func OnExit() {
log.Println("Exit...")
}
func main() {
flag.IntVar(&Port, "port", 9273, "HTTP Server Port")
flag.StringVar(&Password, "password", "", "Password")
flag.IntVar(&Notify, "notify", 1, "Notify")
flag.Parse()
log.Println("Port:", Port, "Password:", Password, "Notify:", Notify)
systray.Run(OnReady, OnExit)
}