新增: 电子相册全屏模式+开机启动+Win10兼容

This commit is contained in:
2026-05-27 01:00:39 +08:00
parent 0cd9cd40b4
commit f3148bf72f
31 changed files with 1290 additions and 490 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
@@ -16,7 +15,7 @@ import (
)
func onSystrayReady() {
systray.SetIcon(generateIcon())
systray.SetIcon(trayIcon)
systray.SetTooltip("动态壁纸引擎")
mSettings := systray.AddMenuItem("桌面设置", "打开设置窗口")
@@ -58,15 +57,20 @@ func onSystrayReady() {
func startWebView() {
runtime.LockOSThread()
log.Println("startWebView: 开始")
workerw := findWorkerW()
if workerw == 0 {
log.Fatal("WorkerW not found")
log.Println("ERROR: WorkerW not found")
showError("无法找到桌面窗口WorkerW程序无法启动。")
os.Exit(1)
}
log.Printf("WorkerW: 0x%x", workerw)
screenW, screenH := getScreenSize()
log.Printf("Screen: %dx%d", screenW, screenH)
log.Println("创建 WebView2...")
wv = webview2.NewWithOptions(webview2.WebViewOptions{
AutoFocus: false,
WindowOptions: webview2.WindowOptions{
@@ -76,8 +80,20 @@ func startWebView() {
},
})
if wv == nil {
log.Fatal("WebView2 create failed")
showError("WebView2 创建失败,请确保已安装 WebView2 Runtime。")
os.Exit(1)
}
log.Println("WebView2 创建成功")
// 立即获取 HWND 并隐藏窗口,避免闪烁
wvHwnd = uintptr(wv.Window())
procShowWindow.Call(wvHwnd, 0) // SW_HIDE
procSetWindowLongPtrW.Call(wvHwnd, gwlStyle, wsPopup|wsVisible|wsChild)
// 立即嵌入 WorkerW
procSetParent.Call(wvHwnd, workerw)
procMoveWindow.Call(wvHwnd, uintptr(^uint(0)), uintptr(^uint(0)), uintptr(screenW+2), uintptr(screenH+2), 1)
log.Printf("已嵌入 WorkerW: HWND=0x%x, %dx%d", wvHwnd, screenW, screenH)
wv.Bind("setZodiacFromGo", func(zodiac string) error {
cfg := loadConfig()
@@ -85,33 +101,22 @@ func startWebView() {
return saveConfig(cfg)
})
wv.SetHtml(buildWallpaperHTML(loadConfig()))
time.Sleep(1 * time.Second)
log.Println("设置 HTML...")
cfg := loadConfig()
wv.SetHtml(buildWallpaperHTML(cfg))
time.Sleep(500 * time.Millisecond)
wvHwnd = uintptr(wv.Window())
procSetWindowLongPtrW.Call(wvHwnd, uintptr(0xFFFFFFF0), uintptr(0x80000000|0x10000000|0x02000000))
// 嵌入完成后再显示
procShowWindow.Call(wvHwnd, 5)
procMoveWindow.Call(wvHwnd, uintptr(^uint(0)), uintptr(^uint(0)), uintptr(screenW+2), uintptr(screenH+2), 1)
log.Printf("壁纸已嵌入: HWND=0x%x, %dx%d", wvHwnd, screenW, screenH)
log.Println("壁纸窗口已显示")
go func() {
time.Sleep(500 * time.Millisecond)
cfg := loadConfig()
evalJS(fmt.Sprintf(`window.userZodiac = %q;`, cfg.Zodiac))
reloadAllCards()
}()
go fullscreenMonitor()
go func() {
time.Sleep(3 * time.Second)
workerw := findWorkerW()
if workerw != 0 {
oldParent, _, _ := procSetParent.Call(wvHwnd, workerw)
log.Printf("SetParent: 0x%x -> 0x%x (old=0x%x)", wvHwnd, workerw, oldParent)
procMoveWindow.Call(wvHwnd, uintptr(^uint(0)), uintptr(^uint(0)), uintptr(screenW+2), uintptr(screenH+2), 1)
}
}()
type msg struct {
hwnd uintptr
message uint32
@@ -139,15 +144,15 @@ func startWebView() {
}
}
}
if m.message == wmSetHtml {
select {
case html := <-htmlQueue:
wv.SetHtml(html)
default:
if m.message == wmSetHtml {
select {
case html := <-htmlQueue:
wv.SetHtml(html)
default:
}
goto nextMsg
}
goto nextMsg
}
nextMsg:
nextMsg:
procTranslateMessage.Call(uintptr(unsafe.Pointer(&m)))
procDispatchMessageW.Call(uintptr(unsafe.Pointer(&m)))
}