Added support for theme setting via env var

This commit is contained in:
root committed 2023-08-16 17:54:35 -04:00
1 parent 300faba252
commit 495322b960
1 file changed
+5 -2
+5 -2
View File
@@ -14,8 +14,11 @@ export enum Color {
}
import { get, writable } from 'svelte/store'
import { env } from '$env/dynamic/public'
const configuredTheme = env.PUBLIC_THEME ?? 'system'
export const theme = writable<'system' | 'light' | 'dark'>(configuredTheme)
export const theme = writable<'system' | 'light' | 'dark'>('system')
export const toggleTheme = () => {
theme.update((theme) => {
@@ -40,7 +43,7 @@ export const inDarkTheme = (): boolean => {
if (typeof localStorage != 'undefined') {
const localTheme: 'system' | 'light' | 'dark' =
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || 'system'
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || configuredTheme
theme.update((theme) => localTheme)