Skip to content

Commit 6dab3cd

Browse files
committed
fix(appearance): 跟随系统主题时, 系统外观切换后同步刷新主题预览
1 parent 75437e2 commit 6dab3cd

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

wind_setting/frontend/src/App.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,19 @@ async function onThemeStyleChange(_themeStyle: string) {
600600
}
601601
}
602602
603+
// 系统外观变化时, 若用户选择"跟随系统", 同步刷新主题预览
604+
// (后端 GetThemePreview 在 themeStyle="system" 时按调用时刻的系统色读取)
605+
const systemDarkMql =
606+
typeof window !== "undefined"
607+
? window.matchMedia("(prefers-color-scheme: dark)")
608+
: null;
609+
async function handleSystemThemeChange() {
610+
const style = formData.value.ui.theme_style || "system";
611+
if (style !== "system") return;
612+
if (!formData.value.ui.theme) return;
613+
await loadThemePreview(formData.value.ui.theme);
614+
}
615+
603616
// 外部链接和工具
604617
async function handleOpenLogFolder() {
605618
try {
@@ -688,13 +701,17 @@ onMounted(async () => {
688701
Show();
689702
} catch {}
690703
});
704+
705+
// 监听系统外观变化, 跟随系统模式下刷新主题预览
706+
systemDarkMql?.addEventListener("change", handleSystemThemeChange);
691707
}
692708
});
693709
694710
onUnmounted(() => {
695711
offConfigEvent();
696712
EventsOff("navigate");
697713
EventsOff("navigate-addword");
714+
systemDarkMql?.removeEventListener("change", handleSystemThemeChange);
698715
});
699716
</script>
700717

0 commit comments

Comments
 (0)