diff --git a/src/app.html b/src/app.html index 6216e56f..c52cff98 100644 --- a/src/app.html +++ b/src/app.html @@ -8,18 +8,35 @@ %sveltekit.head% diff --git a/src/lib/components/chat/Settings/General.svelte b/src/lib/components/chat/Settings/General.svelte index fff8c8fd..35f777a7 100644 --- a/src/lib/components/chat/Settings/General.svelte +++ b/src/lib/components/chat/Settings/General.svelte @@ -4,7 +4,7 @@ import { getLanguages } from '$lib/i18n'; const dispatch = createEventDispatcher(); - import { models, user } from '$lib/stores'; + import { models, user, theme } from '$lib/stores'; const i18n = getContext('i18n'); @@ -15,7 +15,8 @@ // General let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light']; - let theme = 'dark'; + let selectedTheme = 'system'; + let languages = []; let lang = $i18n.language; let notificationEnabled = false; @@ -68,10 +69,11 @@ }; onMount(async () => { + selectedTheme = localStorage.theme ?? 'system'; + let settings = JSON.parse(localStorage.getItem('settings') ?? '{}'); languages = await getLanguages(); - theme = localStorage.theme ?? 'dark'; notificationEnabled = settings.notificationEnabled ?? false; system = settings.system ?? ''; @@ -87,6 +89,35 @@ options = { ...options, ...settings.options }; options.stop = (settings?.options?.stop ?? []).join(','); }); + + const applyTheme = (_theme: string) => { + let themeToApply = _theme; + + if (_theme === 'system') { + themeToApply = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; + } + + themes + .filter((e) => e !== themeToApply) + .forEach((e) => { + e.split(' ').forEach((e) => { + document.documentElement.classList.remove(e); + }); + }); + + themeToApply.split(' ').forEach((e) => { + document.documentElement.classList.add(e); + }); + + console.log(_theme); + }; + + const themeChangeHandler = (_theme: string) => { + theme.set(_theme); + localStorage.setItem('theme', _theme); + + applyTheme(_theme); + };
@@ -99,26 +130,11 @@