Skip to content

Commit 9329b1b

Browse files
committed
Fixed: theme sync
1 parent b3974c4 commit 9329b1b

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

ui/app.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const { userTheme, applyThemePreference, applySystemThemePreference } = useTheme
1818
const { applyPrimaryColor } = useColor();
1919
const settingManager = useSettingManager();
2020
21-
const { fontFamily, primaryColorLight, primaryColorDark, setLang } = settingManager;
21+
const { fontFamily, primaryColorLight, primaryColorDark, setLang, hydrationPromise, isHydrated } = settingManager;
2222
2323
const backgroundColor = computed(() => {
2424
const isDark = userTheme.value === "dark";
@@ -75,6 +75,17 @@ function applyFont(font: string) {
7575
document.documentElement.style.setProperty("--font-heading", font);
7676
}
7777
78+
const applyAfterHydration = async () => {
79+
if (hydrationPromise.value) {
80+
try {
81+
await hydrationPromise.value;
82+
} catch (err) {
83+
console.error("wait hydration failed", err);
84+
}
85+
}
86+
applyCurrentThemeColor();
87+
};
88+
7889
onMounted(async () => {
7990
try {
8091
await useTauriEventListen("primary-color-changed", (event: any) => {
@@ -125,11 +136,21 @@ onMounted(async () => {
125136
});
126137
127138
await useWarmupSetting();
139+
await applyAfterHydration();
128140
} catch (error) {
129141
console.error(error);
130142
}
131143
});
132144
145+
watch(
146+
() => isHydrated.value,
147+
(ready) => {
148+
if (ready) {
149+
applyAfterHydration();
150+
}
151+
}
152+
);
153+
133154
// 切换账号时,按站点映射立即应用语言
134155
watch(
135156
() => currentSite.value,

0 commit comments

Comments
 (0)