fix: make theme toggle respond on first click

This commit is contained in:
illusia committed 2026-09-04 08:05:19 +08:00
1 parent cb3dbe4ca4
commit b0fa4bf5d0
4 files changed
+33 -9

No files matched your search

+9 -1
View File
@@ -17,8 +17,16 @@ export function saveTheme(theme: ThemeMode): void {
applyTheme(theme);
}
export function isDarkTheme(theme: ThemeMode): boolean {
if (theme === "dark") return true;
if (theme === "light") return false;
return typeof window !== "undefined" && typeof window.matchMedia === "function"
? window.matchMedia("(prefers-color-scheme: dark)").matches
: false;
}
export function nextTheme(theme: ThemeMode): ThemeMode {
return theme === "system" ? "light" : theme === "light" ? "dark" : "system";
return isDarkTheme(theme) ? "light" : "dark";
}
applyTheme(getStoredTheme());