-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify.go
More file actions
101 lines (81 loc) · 1.92 KB
/
Copy pathnotify.go
File metadata and controls
101 lines (81 loc) · 1.92 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
package main
import (
"time"
"github.com/astaxie/beego/logs"
"github.com/lxn/walk"
)
var notify *walk.NotifyIcon
func NotifyAction() {
if notify == nil {
NotifyInit()
}
mainWindow.SetVisible(false)
}
func NotifyExit() {
if notify == nil {
return
}
notify.Dispose()
notify = nil
logs.Info("notify exit")
}
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_Main)
if err != nil {
logs.Error("set notify icon fail, %s", err.Error())
return
}
err = notify.SetToolTip(AppNameGet())
if err != nil {
logs.Error("set notify icon fail, %s", err.Error())
return
}
exitBut := walk.NewAction()
err = exitBut.SetText("Shutdown Program")
if err != nil {
logs.Error("notify new action fail, %s", err.Error())
return
}
exitBut.Triggered().Attach(func() {
ConfirmBoxAction(mainWindow, "Do you want to shutdown the program?", CloseWindows)
logs.Info("notify triggered exit")
})
showBut := walk.NewAction()
err = showBut.SetText("Show Window")
if err != nil {
logs.Error("notify new action fail, %s", err.Error())
return
}
showBut.Triggered().Attach(func() {
logs.Info("notify windows set visible true")
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) < time.Second {
logs.Info("notify windows set visible true")
mainWindow.SetVisible(true)
}
lastCheck = now
})
notify.SetVisible(true)
logs.Info("notify init success")
}