From b7e22b33afd91f6cf6216b5cab253b92e24cad26 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Sat, 21 Feb 2026 02:03:58 +0100 Subject: [PATCH] fix: implement robust multi-format icon resolution for system tray --- frontend/dist-electron/main.js | 42 ++++++++++++++++++++++--------- frontend/electron/main.ts | 45 +++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/frontend/dist-electron/main.js b/frontend/dist-electron/main.js index 8d35802..fbe30c0 100644 --- a/frontend/dist-electron/main.js +++ b/frontend/dist-electron/main.js @@ -60,19 +60,37 @@ const initBackend = () => { }; // --- System Tray --- const createTray = () => { - const iconPath = path_1.default.join(electron_1.app.getAppPath(), isDev ? 'assets-build/icon.png' : '../assets-build/icon.png'); - if (!fs_1.default.existsSync(iconPath)) - return; - const icon = electron_1.nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 }); - tray = new electron_1.Tray(icon); - tray.setToolTip('Ultimate Ban Tracker'); - tray.on('click', () => { - if (mainWindow) { - mainWindow.show(); - mainWindow.focus(); + const assetsDir = path_1.default.join(__dirname, '..', 'assets-build'); + const possibleIcons = ['icon.svg', 'icon.png']; + let iconPath = ''; + for (const name of possibleIcons) { + const fullPath = path_1.default.join(assetsDir, name); + if (fs_1.default.existsSync(fullPath)) { + iconPath = fullPath; + break; } - }); - updateTrayMenu(); + } + console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`); + if (!iconPath) { + console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`); + return; + } + try { + const icon = electron_1.nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 }); + tray = new electron_1.Tray(icon); + tray.setToolTip('Ultimate Ban Tracker'); + tray.on('click', () => { + if (mainWindow) { + mainWindow.show(); + mainWindow.focus(); + } + }); + updateTrayMenu(); + console.log(`[Tray] Successfully initialized`); + } + catch (e) { + console.error(`[Tray] Critical error during initialization: ${e.message}`); + } }; const updateTrayMenu = () => { if (!tray) diff --git a/frontend/electron/main.ts b/frontend/electron/main.ts index 6850990..f61e378 100644 --- a/frontend/electron/main.ts +++ b/frontend/electron/main.ts @@ -91,19 +91,40 @@ const initBackend = () => { // --- System Tray --- const createTray = () => { - const iconPath = path.join(app.getAppPath(), isDev ? 'assets-build/icon.png' : '../assets-build/icon.png'); - if (!fs.existsSync(iconPath)) return; - - const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 }); - tray = new Tray(icon); - tray.setToolTip('Ultimate Ban Tracker'); - tray.on('click', () => { - if (mainWindow) { - mainWindow.show(); - mainWindow.focus(); + const assetsDir = path.join(__dirname, '..', 'assets-build'); + const possibleIcons = ['icon.svg', 'icon.png']; + let iconPath = ''; + + for (const name of possibleIcons) { + const fullPath = path.join(assetsDir, name); + if (fs.existsSync(fullPath)) { + iconPath = fullPath; + break; } - }); - updateTrayMenu(); + } + + console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`); + + if (!iconPath) { + console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`); + return; + } + + try { + const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 }); + tray = new Tray(icon); + tray.setToolTip('Ultimate Ban Tracker'); + tray.on('click', () => { + if (mainWindow) { + mainWindow.show(); + mainWindow.focus(); + } + }); + updateTrayMenu(); + console.log(`[Tray] Successfully initialized`); + } catch (e: any) { + console.error(`[Tray] Critical error during initialization: ${e.message}`); + } }; const updateTrayMenu = () => {