diff --git a/.gitignore b/.gitignore index b0a43ef..0d8d42f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ vendor/ # Build u-desktop + +# Web UI +web-ui/node_modules/ +web-ui/dist/ diff --git a/build.ps1 b/build.ps1 index e588d8f..b18f1e0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -12,6 +12,14 @@ $ErrorActionPreference = "Stop" $project = "u-desktop" $buildDir = "dist" +# 构建 Web UI +Write-Host "=== 构建 Web UI ===" -ForegroundColor Cyan +Push-Location web-ui +npm ci --prefer-offline +npm run build +if ($LASTEXITCODE -ne 0) { Write-Host "Web UI 构建失败" -ForegroundColor Red; exit 1 } +Pop-Location + # 清理 if (Test-Path $buildDir) { Remove-Item $buildDir -Recurse -Force } New-Item -ItemType Directory -Force -Path $buildDir | Out-Null diff --git a/wallpaper.go b/wallpaper.go index a0ced6a..b76720e 100644 --- a/wallpaper.go +++ b/wallpaper.go @@ -62,50 +62,33 @@ func buildWallpaperHTML(cfg *Config) string { if cfg.HideWallpaper { bgWrapped = `
` } - html := strings.Replace(overlayHTML, "{{BACKGROUND}}", bgWrapped, 1) - html = strings.Replace(html, "{{LAYOUT}}", string(cfg.Layout), 1) - var bodyClasses []string - if cfg.HideTime { - bodyClasses = append(bodyClasses, "hide-time") - } - if cfg.HideWeather { - bodyClasses = append(bodyClasses, "hide-weather") - } - if cfg.HideZodiac { - bodyClasses = append(bodyClasses, "hide-zodiac") - } - showSec := "false" - if cfg.ShowSeconds { - showSec = "true" - } - html = strings.Replace(html, "{{SHOW_SECONDS}}", showSec, 1) - if cfg.HideAINews { - bodyClasses = append(bodyClasses, "hide-ainews") - } - if cfg.HideKnowledge { - bodyClasses = append(bodyClasses, "hide-knowledge") - } - 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) - } else { - html = strings.Replace(html, " {{BODY_CLASSES}}", "", 1) + initialData := map[string]interface{}{ + "backgroundHtml": bgWrapped, + "layout": string(cfg.Layout), + "showSeconds": cfg.ShowSeconds, + "userZodiac": cfg.Zodiac, + "wallpaperVisible": !cfg.HideWallpaper, + "photoFrameMode": cfg.PhotoFrameMode && cfg.PhotoDir != "", + "cardVisibility": map[string]bool{ + "time": !cfg.HideTime, + "weather": !cfg.HideWeather, + "zodiac": !cfg.HideZodiac, + "knowledge": !cfg.HideKnowledge, + "ainews": !cfg.HideAINews, + "photo": !cfg.HidePhoto, + }, } + dataJSON, _ := json.Marshal(initialData) + inject := fmt.Sprintf(``, string(dataJSON)) // 注入自定义文字 if cfg.WallpaperType == WPTheme && cfg.Theme == ThemeText && cfg.WallpaperText != "" { escaped, _ := json.Marshal(cfg.WallpaperText) - html = strings.Replace(html, "", `window.wallpaperText = `+string(escaped)+`;`, 1) + inject += fmt.Sprintf(``, string(escaped)) } - return html + return strings.Replace(overlayHTML, "", inject+"", 1) } func imageToDataURI(path string) string { @@ -194,7 +177,10 @@ func updateBackground(cfg *Config) { display = ` style="display:none"` } html := fmt.Sprintf(`壁纸 · 布局 · 信息显示
+壁纸 · 布局 · 信息显示
-