diff --git a/src/lib/components/AppLayout.svelte b/src/lib/components/AppLayout.svelte index 11e3680..3c10d44 100644 --- a/src/lib/components/AppLayout.svelte +++ b/src/lib/components/AppLayout.svelte @@ -21,6 +21,7 @@ showSearch, showCommandPalette, theme, + customThemes, focusMode, readOnly, activeNote, @@ -62,7 +63,7 @@ const isMac = navigator.platform.startsWith('Mac'); const isMobile = $derived($platformIsMobile); import { loadVaultState, saveVaultState, readNote, createDailyNote, createBackup, getPendingOpenFile, addQuickAccess, removeQuickAccess, getQuickAccess, setTheme, syncNow, setTaskDone, setTaskPriority, setTaskDue, findOrphanedAttachments, trashOrphanedAttachments } from '$lib/api'; - import { darkThemes, isAndroid } from '$lib/platform'; + import { applyTheme, isAndroid } from '$lib/platform'; import { debounce } from '$lib/utils/debounce'; import { openNoteWindow } from '$lib/utils/window'; import { get } from 'svelte/store'; @@ -509,21 +510,8 @@ } } - function applyTheme(t: string) { - const namedThemes = ['solarized-light', 'solarized-dark', 'catppuccin', 'nord', 'tokyo-night', 'github-light', 'github-dark', 'dracula', 'blueberry', 'forest-green', 'gruvbox', 'midnight-tide', 'cherry-blossom', 'synthwave', 'ember', 'moonlit', 'light-coffee', 'dark-coffee', 'cotton-candy', 'crimson', 'cloud', 'peach', 'material-dark', 'material-light', 'monokai', 'rose-pine', 'everforest', 'horizon', 'cyberpunk', 'black', 'one-dark']; - const root = document.documentElement; - root.classList.remove('dark'); - root.removeAttribute('data-theme'); - if (namedThemes.includes(t)) { - root.setAttribute('data-theme', t); - if (darkThemes.includes(t)) root.classList.add('dark'); - } else if (t === 'dark' || (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) { - root.classList.add('dark'); - } - } - $effect(() => { - applyTheme($theme); + applyTheme($theme, $customThemes); }); $effect(() => { @@ -605,10 +593,10 @@ prefetchPromise = readNote(lastNotePath).catch(() => null); } - applyTheme($theme); + applyTheme($theme, $customThemes); window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { - if ($theme === 'system') applyTheme('system'); + if ($theme === 'system') applyTheme('system', $customThemes); }); // Run sidebar and note list refresh in parallel diff --git a/src/lib/components/CommandPalette.svelte b/src/lib/components/CommandPalette.svelte index 75289bf..a35545c 100644 --- a/src/lib/components/CommandPalette.svelte +++ b/src/lib/components/CommandPalette.svelte @@ -1,7 +1,7 @@ {#if $showCommandPalette} diff --git a/src/lib/components/NoteWindow.svelte b/src/lib/components/NoteWindow.svelte index 4634cee..95a15b0 100644 --- a/src/lib/components/NoteWindow.svelte +++ b/src/lib/components/NoteWindow.svelte @@ -9,7 +9,8 @@ editorDirty, readOnly, sourceMode, - theme + theme, + customThemes } from '$lib/stores/app'; import { readNote } from '$lib/api'; import { keybindings, matchAction } from '$lib/keybindings'; @@ -17,7 +18,7 @@ let { notePath }: { notePath: string } = $props(); - import { darkThemes } from '$lib/platform'; + import { applyTheme } from '$lib/platform'; const appWindow = getCurrentWindow(); const isMac = navigator.platform.startsWith('Mac'); @@ -37,17 +38,7 @@ }); $effect(() => { - const t = $theme || 'system'; - const namedThemes = ['solarized-light', 'solarized-dark', 'catppuccin', 'nord', 'tokyo-night', 'github-light', 'github-dark', 'dracula', 'blueberry', 'forest-green', 'gruvbox', 'midnight-tide', 'cherry-blossom', 'synthwave', 'ember', 'moonlit', 'light-coffee', 'dark-coffee', 'cotton-candy', 'crimson', 'cloud', 'peach', 'material-dark', 'material-light', 'monokai', 'rose-pine', 'everforest', 'horizon', 'cyberpunk', 'black', 'one-dark']; - const root = document.documentElement; - root.classList.remove('dark'); - root.removeAttribute('data-theme'); - if (namedThemes.includes(t)) { - root.setAttribute('data-theme', t); - if (darkThemes.includes(t)) root.classList.add('dark'); - } else if (t === 'dark' || (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) { - root.classList.add('dark'); - } + applyTheme($theme || 'system', $customThemes); }); let lastMouseDown = 0; diff --git a/src/lib/components/SettingsPanel.svelte b/src/lib/components/SettingsPanel.svelte index e6860b5..0689941 100644 --- a/src/lib/components/SettingsPanel.svelte +++ b/src/lib/components/SettingsPanel.svelte @@ -1,7 +1,7 @@