diff --git a/src/lib/ui/colors.ts b/src/lib/ui/colors.ts index 25baf4c0..3701aa42 100644 --- a/src/lib/ui/colors.ts +++ b/src/lib/ui/colors.ts @@ -13,7 +13,7 @@ export enum Color { 'borderDark' = 'border border-slate-200 dark:border-zinc-800 bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200 hover:dark:bg-zinc-800', } -import { writable } from 'svelte/store' +import { get, writable } from 'svelte/store' export const theme = writable<'system' | 'light' | 'dark'>('system') @@ -29,6 +29,15 @@ export const toggleTheme = () => { }) } +export const inDarkTheme = (): boolean => { + if (typeof window != 'undefined') { + return get(theme) == 'system' + ? window.matchMedia('(prefers-color-scheme: dark)').matches + : get(theme) == 'dark' + } + return false +} + if (typeof localStorage != 'undefined') { const localTheme: 'system' | 'light' | 'dark' = (localStorage.getItem('theme') as 'system' | 'light' | 'dark') || 'system' diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 0831d260..beaa47d2 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -11,6 +11,7 @@ // @ts-ignore import { pwaInfo } from 'virtual:pwa-info' import PwaReload from '$lib/PwaReload.svelte' + import { inDarkTheme } from '$lib/ui/colors.js' nProgress.configure({ minimum: 0.4, @@ -37,6 +38,7 @@ + {@html webManifest} diff --git a/vite.config.ts b/vite.config.ts index bbf33287..a2c9a53d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,6 +30,7 @@ export default defineConfig({ purpose: 'masked any', }, ], + start_url: '/', }, }), ],