-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmain_windows.go
More file actions
85 lines (75 loc) · 1.87 KB
/
Copy pathmain_windows.go
File metadata and controls
85 lines (75 loc) · 1.87 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
//go:build windows
package main
import (
"github.com/getlantern/systray"
"github.com/lxn/win"
"golang.design/x/hotkey"
)
var showWindow = true
var programHotkey = hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModAlt}, hotkey.KeyB)
func Platform_ShowOrHiddenWindow() {
consoleWindow := win.GetConsoleWindow()
if showWindow {
Log("Debug-ShowOrHiddenWindow", GetLangText("Debug-ShowOrHiddenWindow_HideWindow"), false)
showWindow = false
win.ShowWindow(consoleWindow, win.SW_HIDE)
} else {
Log("Debug-ShowOrHiddenWindow", GetLangText("Debug-ShowOrHiddenWindow_ShowWindow"), false)
showWindow = true
win.ShowWindow(consoleWindow, win.SW_SHOW)
}
}
func Platform_Stop() {
programHotkey.Unregister()
systray.Quit()
}
func RegHotKey() {
if !needRegHotKey {
return
}
err := programHotkey.Register()
if err != nil {
Log("RegHotKey", GetLangText("Error-RegHotkey"), false, err.Error())
return
}
Log("RegHotKey", GetLangText("Success-RegHotkey"), false)
for range programHotkey.Keydown() {
Platform_ShowOrHiddenWindow()
}
}
func RegSysTray() {
if needHideSystray {
return
}
systray.Run(func() {
defer RecoverAndStop("RegSysTray.onReady", true)
systray.SetIcon(icon_Windows)
systray.SetTitle(programName)
mShow := systray.AddMenuItem("显示/隐藏", "显示/隐藏程序")
mQuit := systray.AddMenuItem("退出", "退出程序")
GoWithCrashLog("RegSysTray.loop", func() {
for {
select {
case <-mShow.ClickedCh:
Platform_ShowOrHiddenWindow()
case <-mQuit.ClickedCh:
systray.Quit()
}
}
})
}, func() {
defer RecoverAndStop("RegSysTray.onExit", true)
ReqStop()
})
}
func main() {
defer RecoverAndStop("main_windows", true)
if PrepareEnv() {
if needHideWindow && showWindow {
Platform_ShowOrHiddenWindow()
}
GoWithCrashLog("RegHotKey", RegHotKey)
GoWithCrashLog("RegSysTray", RegSysTray)
RunConsole()
}
}