修复: 组件隐藏状态启动不生效+相册显示开关

- body class 改用 {{BODY_CLASSES}} 模板变量替换,修复隐藏状态在启动时未应用
- 相册组件添加显示/隐藏开关
This commit is contained in:
2026-05-26 12:29:32 +08:00
parent 92bca936d8
commit 0cd9cd40b4
6 changed files with 27 additions and 4 deletions

View File

@@ -63,6 +63,7 @@ type Config struct {
ShowSeconds bool `json:"showSeconds"`
PhotoDir string `json:"photoDir"`
PhotoInterval int `json:"photoInterval"`
HidePhoto bool `json:"hidePhoto"`
KnowledgeKeyword string `json:"knowledgeKeyword"`
KnowledgePrompt string `json:"knowledgePrompt"`
HideKnowledge bool `json:"hideKnowledge"`

View File

@@ -93,7 +93,7 @@ func pushCurrentPhoto(interval int) {
func startPhotoLoop() {
cfg := loadConfig()
if cfg.PhotoDir == "" {
if cfg.PhotoDir == "" || cfg.HidePhoto {
return
}

View File

@@ -140,6 +140,7 @@ func openSettingsWindow() {
"ainewsCard": !cfg.HideAINews,
"photoDir": cfg.PhotoDir,
"photoInterval": cfg.PhotoInterval,
"photoCard": !cfg.HidePhoto,
})
return string(data)
})
@@ -178,6 +179,17 @@ func openSettingsWindow() {
cfg.ShowSeconds = v
evalJS(fmt.Sprintf("if(window.setShowSeconds) setShowSeconds(%v)", v))
}
if v, ok := data["photoCard"]; ok {
cfg.HidePhoto = !v
evalJS(fmt.Sprintf("if(window.setCardVisible) setCardVisible('photo',%v)", v))
if cfg.PhotoDir != "" {
if v {
restartPhotoLoop()
} else {
stopPhotoLoop()
}
}
}
saveConfig(cfg)
return ""
})

View File

@@ -106,9 +106,14 @@ func buildWallpaperHTML(cfg *Config) string {
if cfg.HideKnowledge {
bodyClasses = append(bodyClasses, "hide-knowledge")
}
if cfg.HidePhoto {
bodyClasses = append(bodyClasses, "hide-photo")
}
if len(bodyClasses) > 0 {
cls := strings.Join(bodyClasses, " ")
html = strings.Replace(html, `layout-`+string(cfg.Layout), `layout-`+string(cfg.Layout)+" "+cls, 1)
html = strings.Replace(html, "{{BODY_CLASSES}}", cls, 1)
} else {
html = strings.Replace(html, " {{BODY_CLASSES}}", "", 1)
}
// 注入自定义文字

View File

@@ -367,6 +367,7 @@ body.hide-ainews #card-ainews,
body.hide-ainews #info .ainews-section { display: none !important; }
body.hide-knowledge #card-knowledge,
body.hide-knowledge #info .knowledge-section { display: none !important; }
body.hide-photo #card-photo { display: none !important; }
/* ===== 相册 ===== */
#card-photo {
@@ -418,7 +419,7 @@ body.hide-knowledge #info .knowledge-section { display: none !important; }
}
</style>
</head>
<body class="layout-{{LAYOUT}}">
<body class="layout-{{LAYOUT}} {{BODY_CLASSES}}">
{{BACKGROUND}}
<!-- ===== SINGLE 布局 ===== -->

View File

@@ -334,6 +334,10 @@ input[type="text"]:focus { border-color: var(--input-border-focus); }
<div class="section">
<div class="section-label">相册</div>
<div class="card">
<div class="item">
<div><div class="item-label">相册展示</div></div>
<label class="switch"><input type="checkbox" id="photoCard" checked><span class="track"><span class="thumb"></span></span></label>
</div>
<div class="item">
<div class="item-desc" id="photoDirDisplay">未选择目录</div>
<div class="btn-group">
@@ -393,7 +397,7 @@ input[type="text"]:focus { border-color: var(--input-border-focus); }
<div class="footer">u-desktop v1.0</div>
<script>
var toggleKeys = ['wallpaper', 'time', 'showSeconds', 'weather', 'zodiacCard', 'knowledgeCard', 'ainewsCard'];
var toggleKeys = ['wallpaper', 'time', 'showSeconds', 'weather', 'zodiacCard', 'knowledgeCard', 'ainewsCard', 'photoCard'];
var initDone = false;
function sendToggle() {
if (!initDone) return;