diff --git a/lib/store.ts b/lib/store.ts index 1654632..d92a9db 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -111,6 +111,10 @@ interface PersistedState { lastSkippedVersion: string | undefined hideStartup: boolean + + themeV2: { + tray: 'light' | 'dark' | undefined + } } const getStorage = (store: LazyStore): StateStorage => ({ @@ -253,6 +257,10 @@ export const usePersistedStore = create()( lastSkippedVersion: undefined, hideStartup: false, + + themeV2: { + tray: undefined, + }, }), { name: 'store', diff --git a/lib/tray.ts b/lib/tray.ts index f2776ee..8e9f169 100644 --- a/lib/tray.ts +++ b/lib/tray.ts @@ -1,5 +1,4 @@ import * as Sentry from '@sentry/browser' -import { invoke } from '@tauri-apps/api/core' import { Menu } from '@tauri-apps/api/menu' import { MenuItem } from '@tauri-apps/api/menu' import { resolveResource } from '@tauri-apps/api/path' @@ -9,6 +8,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,20 +24,44 @@ async function getTray() { } async function resolveTrayIconForTheme() { + const existingTheme = usePersistedStore.getState().themeV2 + + if ('tray' in existingTheme && existingTheme.tray) { + return existingTheme.tray === 'dark' + ? 'icons/favicon/icon.png' + : 'icons/favicon/icon-light.png' + } + let theme: 'light' | 'dark' = 'dark' - try { - if (platform() === 'macos') { - const t = (await invoke('get_system_theme')) || 'dark' - theme = t === 'dark' ? 'dark' : 'light' - } else { + + if (platform() === 'windows') { + try { const currentWindow = getCurrentWindow() - const t = await currentWindow.theme() - theme = t === 'dark' ? 'dark' : 'light' + const windowTheme = await currentWindow.theme() + + theme = windowTheme === 'dark' ? 'dark' : 'light' + } catch {} + } else if (platform() !== 'macos') { + 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 = 'light' } - } catch {} + } console.log('[resolveTrayIconForTheme] theme', theme) + usePersistedStore.setState({ themeV2: { tray: theme } }) + const pickedPath = theme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' console.log('[resolveTrayIconForTheme] pickedPath', pickedPath) @@ -119,13 +143,15 @@ export async function showDefaultTray() { } export async function initTray() { - try { - console.log('[initTray]') + console.log('[initTray] platform', platform()) + try { const initialIcon = await resolveTrayIconForTheme() + console.log('[initTray] initialIcon', initialIcon) + await TrayIcon.new({ id: 'main-tray', - icon: initialIcon!, + icon: initialIcon, tooltip: 'Rclone', menuOnLeftClick: true, action: async (event: TrayIconEvent) => { diff --git a/src-tauri/icons/favicon/icon-light.png b/src-tauri/icons/favicon/icon-light.png index ad31977..538315b 100644 Binary files a/src-tauri/icons/favicon/icon-light.png and b/src-tauri/icons/favicon/icon-light.png differ diff --git a/src-tauri/icons/favicon/icon.png b/src-tauri/icons/favicon/icon.png index 5bed538..171298e 100644 Binary files a/src-tauri/icons/favicon/icon.png and b/src-tauri/icons/favicon/icon.png differ