diff --git a/lib/store.ts b/lib/store.ts index 1654632..caf993b 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -111,6 +111,8 @@ interface PersistedState { lastSkippedVersion: string | undefined hideStartup: boolean + + theme: 'light' | 'dark' | undefined } const getStorage = (store: LazyStore): StateStorage => ({ @@ -253,6 +255,8 @@ export const usePersistedStore = create()( lastSkippedVersion: undefined, hideStartup: false, + + theme: undefined, }), { name: 'store', diff --git a/lib/tray.ts b/lib/tray.ts index 5179ce8..5c43d8e 100644 --- a/lib/tray.ts +++ b/lib/tray.ts @@ -9,6 +9,7 @@ import { getAllWindows, getCurrentWindow } from '@tauri-apps/api/window' import { ask } from '@tauri-apps/plugin-dialog' import { platform } from '@tauri-apps/plugin-os' import { buildMenu } from './menu' +import { usePersistedStore } from './store' import { resetMainWindow } from './window' export async function triggerTrayRebuild() { @@ -24,19 +25,41 @@ async function getTray() { } async function resolveTrayIconForTheme() { + const existingTheme = usePersistedStore.getState().theme + if (existingTheme) { + return existingTheme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' + } + let theme: 'light' | 'dark' = 'dark' try { - const oneTheme = (await invoke('get_system_theme')) || 'dark' + const oneTheme = await invoke('get_system_theme') const currentWindow = getCurrentWindow() const twoTheme = await currentWindow.theme() - if (oneTheme === twoTheme) { + if (oneTheme !== twoTheme) { + const answer = await ask( + 'Could not determine your system theme, please select the correct one below', + { + title: 'Hmm...', + okLabel: 'Dark', + cancelLabel: 'Light', + } + ) + + if (answer) { + theme = 'dark' + } else { + theme = 'light' + } + } else { theme = oneTheme } } catch {} console.log('[resolveTrayIconForTheme] theme', theme) + usePersistedStore.setState({ theme }) + const pickedPath = theme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' console.log('[resolveTrayIconForTheme] pickedPath', pickedPath)