fix: implement robust multi-format icon resolution for system tray
This commit is contained in:
@@ -60,9 +60,22 @@ const initBackend = () => {
|
|||||||
};
|
};
|
||||||
// --- System Tray ---
|
// --- System Tray ---
|
||||||
const createTray = () => {
|
const createTray = () => {
|
||||||
const iconPath = path_1.default.join(electron_1.app.getAppPath(), isDev ? 'assets-build/icon.png' : '../assets-build/icon.png');
|
const assetsDir = path_1.default.join(__dirname, '..', 'assets-build');
|
||||||
if (!fs_1.default.existsSync(iconPath))
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`);
|
||||||
|
if (!iconPath) {
|
||||||
|
console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
const icon = electron_1.nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
|
const icon = electron_1.nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
|
||||||
tray = new electron_1.Tray(icon);
|
tray = new electron_1.Tray(icon);
|
||||||
tray.setToolTip('Ultimate Ban Tracker');
|
tray.setToolTip('Ultimate Ban Tracker');
|
||||||
@@ -73,6 +86,11 @@ const createTray = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateTrayMenu();
|
updateTrayMenu();
|
||||||
|
console.log(`[Tray] Successfully initialized`);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error(`[Tray] Critical error during initialization: ${e.message}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const updateTrayMenu = () => {
|
const updateTrayMenu = () => {
|
||||||
if (!tray)
|
if (!tray)
|
||||||
|
|||||||
@@ -91,9 +91,26 @@ const initBackend = () => {
|
|||||||
|
|
||||||
// --- System Tray ---
|
// --- System Tray ---
|
||||||
const createTray = () => {
|
const createTray = () => {
|
||||||
const iconPath = path.join(app.getAppPath(), isDev ? 'assets-build/icon.png' : '../assets-build/icon.png');
|
const assetsDir = path.join(__dirname, '..', 'assets-build');
|
||||||
if (!fs.existsSync(iconPath)) return;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 });
|
const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
|
||||||
tray = new Tray(icon);
|
tray = new Tray(icon);
|
||||||
tray.setToolTip('Ultimate Ban Tracker');
|
tray.setToolTip('Ultimate Ban Tracker');
|
||||||
@@ -104,6 +121,10 @@ const createTray = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateTrayMenu();
|
updateTrayMenu();
|
||||||
|
console.log(`[Tray] Successfully initialized`);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error(`[Tray] Critical error during initialization: ${e.message}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateTrayMenu = () => {
|
const updateTrayMenu = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user