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

@@ -3,6 +3,7 @@ package main
import (
_ "embed"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"os"
@@ -44,35 +45,14 @@ var themeMap = map[ThemeName]string{
func buildWallpaperHTML(cfg *Config) string {
var bg string
switch cfg.WallpaperType {
case WPTheme:
if cfg.WallpaperType == WPTheme {
if t, ok := themeMap[cfg.Theme]; ok {
bg = t
} else {
bg = themeAurora
}
case WPImage:
if cfg.ImagePath != "" {
src := imageToDataURI(cfg.ImagePath)
if src != "" {
bg = fmt.Sprintf(`<img src="%s" style="position:fixed;top:0;left:0;width:100%%;height:100%%;object-fit:cover;z-index:1;">`, src)
}
}
case WPBing:
if p := getCurrentBingPath(); p != "" {
if _, err := os.Stat(p); err == nil {
src := imageToDataURI(p)
if src != "" {
bg = fmt.Sprintf(`<img src="%s" style="position:fixed;top:0;left:0;width:100%%;height:100%%;object-fit:cover;z-index:1;">`, src)
}
}
}
case WPColor:
if cfg.ColorGradient && cfg.Color2 != "" {
bg = fmt.Sprintf(`<div style="position:fixed;top:0;left:0;width:100%%;height:100%%;z-index:1;background:linear-gradient(135deg,%s,%s);"></div>`, cfg.Color1, cfg.Color2)
} else {
bg = fmt.Sprintf(`<div style="position:fixed;top:0;left:0;width:100%%;height:100%%;z-index:1;background:%s;"></div>`, cfg.Color1)
}
} else {
bg = buildBgHTML(cfg)
}
if bg == "" {
@@ -109,6 +89,9 @@ func buildWallpaperHTML(cfg *Config) string {
if cfg.HidePhoto {
bodyClasses = append(bodyClasses, "hide-photo")
}
if cfg.PhotoFrameMode && cfg.PhotoDir != "" {
bodyClasses = append(bodyClasses, "photo-frame-mode")
}
if len(bodyClasses) > 0 {
cls := strings.Join(bodyClasses, " ")
html = strings.Replace(html, "{{BODY_CLASSES}}", cls, 1)
@@ -118,9 +101,8 @@ func buildWallpaperHTML(cfg *Config) string {
// 注入自定义文字
if cfg.WallpaperType == WPTheme && cfg.Theme == ThemeText && cfg.WallpaperText != "" {
escaped := strings.ReplaceAll(cfg.WallpaperText, `\`, `\\`)
escaped = strings.ReplaceAll(escaped, `"`, `\"`)
html = strings.Replace(html, "</script>", `window.wallpaperText = "`+escaped+`";</script>`, 1)
escaped, _ := json.Marshal(cfg.WallpaperText)
html = strings.Replace(html, "</script>", `window.wallpaperText = `+string(escaped)+`;</script>`, 1)
}
return html
@@ -152,21 +134,95 @@ func reloadWallpaper() {
return
}
cfg := loadConfig()
// 非主题壁纸切换:仅替换 #bg-layer不销毁卡片状态
if cfg.WallpaperType != WPTheme {
updateBackground(cfg)
return
}
// 主题切换需要 SetHtmlcanvas+script之后恢复卡片数据
html := buildWallpaperHTML(cfg)
select {
case htmlQueue <- html:
default:
}
procPostMessageW.Call(wvHwnd, wmSetHtml, 0, 0)
go func() {
time.Sleep(1 * time.Second)
evalJS(fmt.Sprintf(`window.userZodiac = %q;`, cfg.Zodiac))
if cfg.Theme == ThemeText && cfg.WallpaperText != "" {
evalJS(fmt.Sprintf(`window.wallpaperText = %q; var el=document.getElementById("wallpaper-text"); if(el){el.textContent=%q;}`, cfg.WallpaperText, cfg.WallpaperText))
go reloadAllCards()
}
func buildBgHTML(cfg *Config) string {
switch cfg.WallpaperType {
case WPImage:
if cfg.ImagePath != "" {
src := imageToDataURI(cfg.ImagePath)
if src != "" {
return buildCoverImgHTML(src)
}
}
city := getCurrentCity()
case WPBing:
if p := getCurrentBingPath(); p != "" {
if _, err := os.Stat(p); err == nil {
src := imageToDataURI(p)
if src != "" {
return buildCoverImgHTML(src)
}
}
}
case WPColor:
if cfg.ColorGradient && cfg.Color2 != "" {
return fmt.Sprintf(`<div style="position:fixed;top:0;left:0;width:100%%;height:100%%;z-index:1;background:linear-gradient(135deg,%s,%s);"></div>`, cfg.Color1, cfg.Color2)
}
return fmt.Sprintf(`<div style="position:fixed;top:0;left:0;width:100%%;height:100%%;z-index:1;background:%s;"></div>`, cfg.Color1)
}
return ""
}
const coverImgTpl = `<img src="%s" style="position:fixed;top:0;left:0;width:100%%;height:100%%;object-fit:cover;z-index:1;">`
func buildCoverImgHTML(src string) string {
return fmt.Sprintf(coverImgTpl, src)
}
func updateBackground(cfg *Config) {
bg := buildBgHTML(cfg)
if bg == "" {
return
}
display := ""
if cfg.HideWallpaper {
display = ` style="display:none"`
}
html := fmt.Sprintf(`<div id="bg-layer"%s>%s</div>`, display, bg)
evalJS(fmt.Sprintf(`var el=document.getElementById('bg-layer'); if(el){el.outerHTML=%q;}`, html))
}
func reloadAllCards() {
time.Sleep(800 * time.Millisecond)
evalJS(fmt.Sprintf(`window.userZodiac = %q;`, loadConfig().Zodiac))
if cached := loadHoroscopeCache(); cached != nil {
pushHoroscopeInfo(cached)
}
if cached := loadAINewsCache(); cached != nil {
pushAINews(cached)
}
cfg := loadConfig()
if cfg.KnowledgeKeyword != "" && !cfg.HideKnowledge {
if cached := getRandomKnowledgeCard(cfg.KnowledgeKeyword); cached != "" {
pushKnowledgeJSON(cached, cfg.KnowledgeKeyword)
}
}
if city := getCurrentCity(); city.ID != "" {
go fetchAndPushWeather(city)
}()
}
if cfg.PhotoDir != "" && !cfg.HidePhoto {
go func() {
time.Sleep(500 * time.Millisecond)
pushCurrentPhoto(cfg.PhotoInterval)
}()
}
}
func bingReloadImage() {