重构: 拆分main.go为5个文件 + 壁纸HTML移至web目录
- main.go: 入口+单实例互斥锁 - win32.go: Win32 API/embed/evalJS/全局变量 - config.go: 配置读写+图标生成 - weather.go: 天气API/定位/天气循环 - systray.go: 托盘菜单/WebView/全屏监控 - wallpaper.html → web/wallpaper.html
This commit is contained in:
84
win32.go
Normal file
84
win32.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
"unsafe"
|
||||
|
||||
"github.com/jchv/go-webview2"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
//go:embed web/wallpaper.html
|
||||
var fs embed.FS
|
||||
|
||||
var (
|
||||
user32 = windows.NewLazySystemDLL("user32.dll")
|
||||
procFindWindowW = user32.NewProc("FindWindowW")
|
||||
procFindWindowExW = user32.NewProc("FindWindowExW")
|
||||
procSendMessageTimeoutW = user32.NewProc("SendMessageTimeoutW")
|
||||
procSetParent = user32.NewProc("SetParent")
|
||||
procGetForegroundWindow = user32.NewProc("GetForegroundWindow")
|
||||
procGetWindowRect = user32.NewProc("GetWindowRect")
|
||||
procGetSystemMetrics = user32.NewProc("GetSystemMetrics")
|
||||
procMoveWindow = user32.NewProc("MoveWindow")
|
||||
procShowWindow = user32.NewProc("ShowWindow")
|
||||
procSetProcessDPIAware = user32.NewProc("SetProcessDPIAware")
|
||||
procSetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW")
|
||||
procGetMessageW = user32.NewProc("GetMessageW")
|
||||
procPostMessageW = user32.NewProc("PostMessageW")
|
||||
procTranslateMessage = user32.NewProc("TranslateMessage")
|
||||
procDispatchMessageW = user32.NewProc("DispatchMessageW")
|
||||
)
|
||||
|
||||
var wv webview2.WebView
|
||||
var wvHwnd uintptr
|
||||
var jsQueue = make(chan string, 64)
|
||||
var paused int32
|
||||
|
||||
const wmEvalJS = 0x0401
|
||||
|
||||
func evalJS(js string) {
|
||||
select {
|
||||
case jsQueue <- js:
|
||||
log.Println("evalJS queued:", js[:min(len(js), 60)])
|
||||
default:
|
||||
log.Println("jsQueue full, dropping eval")
|
||||
}
|
||||
if wvHwnd != 0 {
|
||||
procPostMessageW.Call(wvHwnd, wmEvalJS, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func findWorkerW() uintptr {
|
||||
progman, _, _ := procFindWindowW.Call(
|
||||
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Progman"))), 0)
|
||||
if progman == 0 {
|
||||
return 0
|
||||
}
|
||||
var result uintptr
|
||||
procSendMessageTimeoutW.Call(progman, 0x052C, 0, 0, 0x0000, 1000, uintptr(unsafe.Pointer(&result)))
|
||||
shellDefView, _, _ := procFindWindowExW.Call(progman, 0,
|
||||
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("SHELLDLL_DefView"))), 0)
|
||||
workerwAfterShell, _, _ := procFindWindowExW.Call(progman, shellDefView,
|
||||
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("WorkerW"))), 0)
|
||||
if workerwAfterShell != 0 {
|
||||
return workerwAfterShell
|
||||
}
|
||||
ww, _, _ := procFindWindowExW.Call(progman, 0,
|
||||
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("WorkerW"))), 0)
|
||||
return ww
|
||||
}
|
||||
|
||||
func getScreenSize() (int32, int32) {
|
||||
w, _, _ := procGetSystemMetrics.Call(0)
|
||||
h, _, _ := procGetSystemMetrics.Call(1)
|
||||
return int32(w), int32(h)
|
||||
}
|
||||
Reference in New Issue
Block a user