From 495322b96034c519aae2bcf8e5a0cd7d2094a5de Mon Sep 17 00:00:00 2001 From: root Date: Wed, 16 Aug 2023 17:54:35 -0400 Subject: [PATCH] Added support for theme setting via env var --- src/lib/ui/colors.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/ui/colors.ts b/src/lib/ui/colors.ts index 3701aa42..13442d71 100644 --- a/src/lib/ui/colors.ts +++ b/src/lib/ui/colors.ts @@ -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)