-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaitranslate.go
64 lines (54 loc) · 1.42 KB
/
aitranslate.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
package main
import (
"flag"
"github.com/cnbattle/aitranslate/pkg/icon"
"github.com/gen2brain/beeep"
"github.com/getlantern/systray"
"github.com/skratchdot/open-golang/open"
)
var (
// 翻译渠道
channel string
)
func init() {
initFile()
flag.StringVar(&channel, "c", "Google", "translate channel: Google or YouDao.")
flag.Parse()
}
func main() {
go translates()
systray.Run(onReady, func() {})
}
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("AiTranslate")
go func() {
systray.SetTitle("AiTranslate")
systray.AddMenuItem("翻译渠道", "").Disable()
google := systray.AddMenuItem("Google Translate", "Google Translate")
youdao := systray.AddMenuItem("YouDao Translate", "YouDao Translate")
systray.AddMenuItem("=====", "").Disable()
githubUrl := systray.AddMenuItem("Visit Github", "Visit Github")
quit := systray.AddMenuItem("退出", "Quit the whole app")
systray.AddSeparator()
for {
select {
case <-google.ClickedCh:
google.Disable()
youdao.Enable()
channel = "Google"
beeep.Alert("Change", "Use Google Translate now.", getImagePath("logo"))
case <-youdao.ClickedCh:
youdao.Disable()
google.Enable()
channel = "YouDao"
beeep.Alert("Change", "Use YouDao Translate now.", getImagePath("logo"))
case <-githubUrl.ClickedCh:
open.Run("https://github.com/cnbattle/aitranslate")
case <-quit.ClickedCh:
systray.Quit()
return
}
}
}()
}