fix: implement robust multi-format icon resolution for system tray

This commit is contained in:
2026-02-21 02:03:58 +01:00
parent 20b41d90ab
commit b7e22b33af
2 changed files with 63 additions and 24 deletions

View File

@@ -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 = () => {