diff --git a/src/lib/util/theme.ts b/src/lib/util/theme.ts index 940c66b7..033bbe39 100644 --- a/src/lib/util/theme.ts +++ b/src/lib/util/theme.ts @@ -1,10 +1,15 @@ import { writable } from 'svelte/store'; +import type { Writable } from 'svelte/store'; import { persist, localStorage } from '@macfja/svelte-persistent-store'; -export const themeStore = persist( +export interface ThemeConfig { + isDark: boolean; + theme?: string; +} + +export const themeStore: Writable = persist( writable({ - isDark: false, - theme: '' + isDark: false }), localStorage(), 'themeStore' diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 9360b60a..8b6dd0cb 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -24,8 +24,8 @@ const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; - if (isDarkMode && $themeStore.theme === '') { - setTheme('dark'); + if ($themeStore.theme === undefined) { + setTheme(isDarkMode ? 'dark' : 'light'); } themeStore.subscribe(({ theme, isDark }) => {