diff --git a/lib/store.ts b/lib/store.ts index caf993b..2c66b82 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -112,7 +112,9 @@ interface PersistedState { hideStartup: boolean - theme: 'light' | 'dark' | undefined + theme: { + tray: 'light' | 'dark' | undefined + } } const getStorage = (store: LazyStore): StateStorage => ({ @@ -256,7 +258,9 @@ export const usePersistedStore = create()( hideStartup: false, - theme: undefined, + theme: { + tray: undefined, + }, }), { name: 'store', diff --git a/lib/tray.ts b/lib/tray.ts index 3c87983..638a728 100644 --- a/lib/tray.ts +++ b/lib/tray.ts @@ -25,41 +25,66 @@ 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' - // } + const existingTheme = usePersistedStore.getState().theme + + if (typeof existingTheme === 'string') { + usePersistedStore.setState({ theme: { tray: undefined } }) + } + + if (existingTheme.tray) { + return existingTheme.tray === 'dark' + ? 'icons/favicon/icon.png' + : 'icons/favicon/icon-light.png' + } let theme: 'light' | 'dark' = 'dark' - try { - const detectedTheme = (await invoke('get_system_theme')) as - | 'light' - | 'dark' - | 'unknown' - if (detectedTheme === 'unknown') { - const answer = await ask( - 'Could not determine your system theme, please select the correct one below', - { - title: 'Hmm...', - okLabel: 'Dark', - cancelLabel: 'Light', + if (['macos', 'windows'].includes(platform())) { + try { + const detectedTheme = (await invoke('get_system_theme')) as + | 'light' + | 'dark' + | 'unknown' + + if (detectedTheme === 'unknown') { + 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' } - ) - - if (answer) { - theme = 'dark' } else { - theme = 'light' + theme = detectedTheme } + } catch {} + } else { + const answer = await ask( + 'Based on your tray/menubar, how do you want the icon to look?\n\nIf your menubar has a dark background select light, otherwise select dark.', + { + title: 'Greetings, Linux User', + okLabel: 'Dark', + cancelLabel: 'Light', + } + ) + + if (answer) { + theme = 'dark' } else { - theme = detectedTheme + theme = 'light' } - } catch {} + } console.log('[resolveTrayIconForTheme] theme', theme) - usePersistedStore.setState({ theme: undefined }) + usePersistedStore.setState({ theme: { tray: theme } }) const pickedPath = theme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' console.log('[resolveTrayIconForTheme] pickedPath', pickedPath)