-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
102 lines (83 loc) · 1.77 KB
/
notify.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
package main
import (
"github.com/astaxie/beego/logs"
"github.com/lxn/walk"
"time"
)
var notify *walk.NotifyIcon
func NotifyUpdateIcon(icon *walk.Icon) {
if notify == nil {
return
}
notify.SetIcon(icon)
}
func NotifyUpdateFlow(flow string) {
if notify == nil {
return
}
notify.SetToolTip(flow)
}
func Notify() {
if notify == nil {
NotifyInit()
}
mainWindow.SetVisible(false)
}
func NotifyExit() {
if notify == nil {
return
}
notify.Dispose()
notify = nil
}
var lastCheck time.Time
func NotifyInit() {
var err error
notify, err = walk.NewNotifyIcon(mainWindow)
if err != nil {
logs.Error("new notify icon fail, %s", err.Error())
return
}
err = notify.SetIcon(ICON_Network_Disable)
if err != nil {
logs.Error("set notify icon fail, %s", err.Error())
return
}
exitBut := walk.NewAction()
err = exitBut.SetText(LangValue("exit"))
if err != nil {
logs.Error("notify new action fail, %s", err.Error())
return
}
exitBut.Triggered().Attach(func() {
walk.App().Exit(0)
})
showBut := walk.NewAction()
err = showBut.SetText(LangValue("showwindows"))
if err != nil {
logs.Error("notify new action fail, %s", err.Error())
return
}
showBut.Triggered().Attach(func() {
mainWindow.SetVisible(true)
})
if err := notify.ContextMenu().Actions().Add(showBut); err != nil {
logs.Error("notify add action fail, %s", err.Error())
return
}
if err := notify.ContextMenu().Actions().Add(exitBut); err != nil {
logs.Error("notify add action fail, %s", err.Error())
return
}
notify.MouseUp().Attach(func(x, y int, button walk.MouseButton) {
if button != walk.LeftButton {
return
}
now := time.Now()
if now.Sub(lastCheck) < 2 * time.Second {
mainWindow.SetVisible(true)
}
lastCheck = now
})
notify.SetVisible(true)
}