新增: 电子相册全屏模式+开机启动+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

@@ -24,6 +24,40 @@ var (
settingsHwnd uintptr
)
const runKeyPath = `Software\Microsoft\Windows\CurrentVersion\Run`
func isAutoStartEnabled() bool {
k, err := registry.OpenKey(registry.CURRENT_USER, runKeyPath, registry.QUERY_VALUE)
if err != nil {
return false
}
defer k.Close()
_, _, err = k.GetStringValue("u-desktop")
return err == nil
}
func setAutoStart(enabled bool) {
exePath, _ := os.Executable()
if enabled {
k, _, err := registry.CreateKey(registry.CURRENT_USER, runKeyPath, registry.SET_VALUE)
if err != nil {
log.Println("注册表写入失败:", err)
return
}
defer k.Close()
k.SetStringValue("u-desktop", exePath)
log.Println("已开启开机启动")
} else {
k, err := registry.OpenKey(registry.CURRENT_USER, runKeyPath, registry.SET_VALUE)
if err != nil {
return
}
defer k.Close()
k.DeleteValue("u-desktop")
log.Println("已关闭开机启动")
}
}
func isSystemLightTheme() bool {
k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Themes\Personalize`, registry.QUERY_VALUE)
if err != nil {
@@ -49,6 +83,25 @@ var themeNames = []struct {
{ThemeText, "文字"},
}
func refreshVisibleCards(cfg, oldCfg *Config) {
if oldCfg.HideWeather && !cfg.HideWeather {
go fetchAndPushWeather(getCurrentCity())
}
if oldCfg.HideZodiac && !cfg.HideZodiac {
triggerHoroscopeRefresh(cfg.Zodiac)
}
if oldCfg.HideKnowledge && !cfg.HideKnowledge {
if cfg.KnowledgeKeyword != "" {
triggerKnowledgeRefresh()
} else {
pushKnowledgePlaceholder()
}
}
if oldCfg.HideAINews && !cfg.HideAINews {
triggerAINewsRefresh()
}
}
func openSettingsWindow() {
settingsMu.Lock()
if settingsOpen && settingsHwnd != 0 {
@@ -113,34 +166,36 @@ func openSettingsWindow() {
}
data, _ := json.Marshal(map[string]interface{}{
"lightTheme": isSystemLightTheme(),
"wallpaper": !cfg.HideWallpaper,
"time": !cfg.HideTime,
"weather": !cfg.HideWeather,
"zodiacCard": !cfg.HideZodiac,
"knowledgeCard": !cfg.HideKnowledge,
"layout": string(cfg.Layout),
"zodiac": cfg.Zodiac,
"city": cfg.City,
"provinces": provinces,
"citiesByProv": citiesByProv,
"wallpaperType": string(cfg.WallpaperType),
"theme": string(cfg.Theme),
"themes": tl,
"color1": cfg.Color1,
"color2": cfg.Color2,
"colorGradient": cfg.ColorGradient,
"savedColors": cfg.SavedColors,
"bingAutoRefresh": cfg.BingAutoRefresh,
"lightTheme": isSystemLightTheme(),
"wallpaper": !cfg.HideWallpaper,
"time": !cfg.HideTime,
"weather": !cfg.HideWeather,
"zodiacCard": !cfg.HideZodiac,
"knowledgeCard": !cfg.HideKnowledge,
"layout": string(cfg.Layout),
"zodiac": cfg.Zodiac,
"city": cfg.City,
"provinces": provinces,
"citiesByProv": citiesByProv,
"wallpaperType": string(cfg.WallpaperType),
"theme": string(cfg.Theme),
"themes": tl,
"color1": cfg.Color1,
"color2": cfg.Color2,
"colorGradient": cfg.ColorGradient,
"savedColors": cfg.SavedColors,
"bingAutoRefresh": cfg.BingAutoRefresh,
"knowledgeKeyword": cfg.KnowledgeKeyword,
"knowledgePrompt": cfg.KnowledgePrompt,
"wallpaperText": cfg.WallpaperText,
"imagePath": cfg.ImagePath,
"showSeconds": cfg.ShowSeconds,
"ainewsCard": !cfg.HideAINews,
"photoDir": cfg.PhotoDir,
"photoInterval": cfg.PhotoInterval,
"photoCard": !cfg.HidePhoto,
"wallpaperText": cfg.WallpaperText,
"imagePath": cfg.ImagePath,
"showSeconds": cfg.ShowSeconds,
"ainewsCard": !cfg.HideAINews,
"photoDir": cfg.PhotoDir,
"photoInterval": cfg.PhotoInterval,
"photoCard": !cfg.HidePhoto,
"photoFrameMode": cfg.PhotoFrameMode,
"autoStart": isAutoStartEnabled(),
})
return string(data)
})
@@ -151,6 +206,7 @@ func openSettingsWindow() {
return ""
}
cfg := loadConfig()
oldCfg := *cfg
if v, ok := data["wallpaper"]; ok {
cfg.HideWallpaper = !v
evalJS(fmt.Sprintf("if(window.setWallpaperVisible) setWallpaperVisible(%v)", v))
@@ -179,9 +235,30 @@ func openSettingsWindow() {
cfg.ShowSeconds = v
evalJS(fmt.Sprintf("if(window.setShowSeconds) setShowSeconds(%v)", v))
}
if v, ok := data["autoStart"]; ok {
setAutoStart(v)
}
if v, ok := data["photoFrameMode"]; ok {
cfg.PhotoFrameMode = v
evalJS(fmt.Sprintf("if(window.setPhotoFrameMode) setPhotoFrameMode(%v)", v))
if v {
cfg.HideWallpaper = true
cfg.HideTime = true
cfg.HideWeather = true
cfg.HideZodiac = true
cfg.HideAINews = true
cfg.HideKnowledge = true
evalJS(`if(window.setWallpaperVisible) setWallpaperVisible(false)`)
for _, card := range []string{"time", "weather", "zodiac", "ainews", "knowledge"} {
evalJS(fmt.Sprintf("if(window.setCardVisible) setCardVisible('%s',false)", card))
}
}
}
if v, ok := data["photoCard"]; ok {
cfg.HidePhoto = !v
saveConfig(cfg)
evalJS(fmt.Sprintf("if(window.setCardVisible) setCardVisible('photo',%v)", v))
refreshVisibleCards(cfg, &oldCfg)
if cfg.PhotoDir != "" {
if v {
restartPhotoLoop()
@@ -189,8 +266,10 @@ func openSettingsWindow() {
stopPhotoLoop()
}
}
} else {
saveConfig(cfg)
refreshVisibleCards(cfg, &oldCfg)
}
saveConfig(cfg)
return ""
})
@@ -416,8 +495,8 @@ func openSettingsWindow() {
hwnd := uintptr(w.Window())
// disable resize
style, _, _ := procGetWindowLongPtrW.Call(hwnd, uintptr(0xFFFFFFF0))
procSetWindowLongPtrW.Call(hwnd, uintptr(0xFFFFFFF0), style & ^uintptr(0x00040000|0x00010000))
style, _, _ := procGetWindowLongPtrW.Call(hwnd, gwlStyle)
procSetWindowLongPtrW.Call(hwnd, gwlStyle, style & ^uintptr(wsSizebox|wsMaxbox))
// resizeToFit: JS measures content, Go adjusts window frame
w.Bind("resizeToFit", func(contentW, contentH int) string {