From 687a007d2676b04b6434d27c95d619f811e0db73 Mon Sep 17 00:00:00 2001 From: Zane <75694352+zanesq@users.noreply.github.com> Date: Tue, 4 Nov 2025 14:06:24 -0800 Subject: [PATCH] improve linux tray icon support (#5425) Co-authored-by: Douwe Osinga --- ui/desktop/src/main.ts | 48 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index b9797198..6fd76def 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -764,30 +764,43 @@ const destroyTray = () => { } }; +const disableTray = () => { + const settings = loadSettings(); + settings.showMenuBarIcon = false; + saveSettings(settings); +}; + const createTray = () => { - // If tray already exists, destroy it first destroyTray(); - const isDev = !app.isPackaged; - let iconPath: string; + const possiblePaths = [ + path.join(process.resourcesPath, 'images', 'iconTemplate.png'), + path.join(process.cwd(), 'src', 'images', 'iconTemplate.png'), + path.join(__dirname, '..', 'images', 'iconTemplate.png'), + path.join(__dirname, 'images', 'iconTemplate.png'), + path.join(process.cwd(), 'images', 'iconTemplate.png'), + ]; - if (isDev) { - iconPath = path.join(process.cwd(), 'src', 'images', 'iconTemplate.png'); - } else { - iconPath = path.join(process.resourcesPath, 'images', 'iconTemplate.png'); + const iconPath = possiblePaths.find((p) => fsSync.existsSync(p)); + + if (!iconPath) { + console.warn('[Main] Tray icon not found. App will continue without system tray.'); + disableTray(); + return; } - tray = new Tray(iconPath); + try { + tray = new Tray(iconPath); + setTrayRef(tray); + updateTrayMenu(getUpdateAvailable()); - // Set tray reference for auto-updater - setTrayRef(tray); - - // Initially build menu based on update status - updateTrayMenu(getUpdateAvailable()); - - // On Windows, clicking the tray icon should show the window - if (process.platform === 'win32') { - tray.on('click', showWindow); + if (process.platform === 'win32') { + tray.on('click', showWindow); + } + } catch (error) { + console.error('[Main] Tray creation failed. App will continue without system tray.', error); + disableTray(); + tray = null; } }; @@ -802,7 +815,6 @@ const showWindow = async () => { return; } - // Define the initial offset values const initialOffsetX = 30; const initialOffsetY = 30;