Compare commits

...

2 Commits

3 changed files with 41 additions and 25 deletions

View File

@@ -13,38 +13,46 @@ let tray = null;
* Creates and configures the cross-platform System Tray. * Creates and configures the cross-platform System Tray.
* *
* Responsibilities: * Responsibilities:
* - Load the appropriate icon for the OS. * - Loads the appropriate icon format based on the operating system.
* - Build the right-click context menu. * - Builds the right-click context menu.
* - Handle left-click behavior (toggle window visibility). * - Handles left-click behavior to toggle main window visibility.
* *
* @param {import('electron').BrowserWindow} mainWindow - The main application window. * @param {import('electron').BrowserWindow} mainWindow - The main application window.
* @param {boolean} devMode - Indicates whether the application is running in development mode.
* @returns {Tray} The created Tray instance. * @returns {Tray} The created Tray instance.
*/ */
function createSystemTray(mainWindow) { function createSystemTray(mainWindow, devMode) {
// Prevent creating multiple instances // Prevent creating multiple tray instances
if (tray) return tray; if (tray) return tray;
/** const isWin = process.platform === "win32";
* Resolve the icon path. const iconName = isWin ? "app-icon.ico" : "app-icon-64x64.png";
* Tip: Use a .png for Linux/macOS and a .ico for Windows for best results.
* Here we use a generic PNG assuming it exists in your resources folder. // Attempt to load the icon from the local build directory first
*/ let iconPath = path.join(__dirname, "..", "build", iconName);
const iconPath = config.devMode ?
path.join(__dirname, "..", "build", "app-icon-64x64.png") : // Fallback to the extracted resources path if running in production
path.join(process.resourcesPath, "build", "app-icon-64x64.png"); if (!devMode && !fs.existsSync(iconPath)) {
iconPath = path.join(process.resourcesPath, iconName);
}
if (!fs.existsSync(iconPath)) { if (!fs.existsSync(iconPath)) {
logger.error(`❌ ERREUR : L'icône du Tray est introuvable à ce chemin : ${iconPath}`); logger.error(`System Tray icon not found at resolved path: ${iconPath}`);
} else { } else {
logger.info(`✅ Icône trouvée pour le Tray !`); logger.info("System Tray icon resolved successfully.");
} }
const icon = nativeImage.createFromPath(iconPath); const icon = nativeImage.createFromPath(iconPath);
if (icon.isEmpty()) {
logger.error("System Tray icon file was found but could not be decoded by Electron (image is empty).");
}
tray = new Tray(icon); tray = new Tray(icon);
tray.setToolTip("Freedom Loader"); tray.setToolTip("Freedom Loader");
/** /**
* The context menu (Right-click). * System Tray Context Menu (Right-click action).
*/ */
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ {
@@ -53,13 +61,13 @@ function createSystemTray(mainWindow) {
mainWindow.show(); mainWindow.show();
}, },
}, },
{type: "separator"}, { type: "separator" },
{ {
label: "Quit", label: "Quit",
click: () => { click: () => {
/** /**
* Tell the app it's a deliberate exit, * Flags the application for a deliberate exit,
* bypassing the "minimize to tray" behavior. * bypassing the default "minimize to tray" behavior.
*/ */
app.isQuitting = true; app.isQuitting = true;
app.quit(); app.quit();
@@ -70,8 +78,8 @@ function createSystemTray(mainWindow) {
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
/** /**
* Left-click behavior: Toggle window visibility. * Left-click behavior: Toggles main window visibility.
* Note: macOS doesn't usually use left-click on tray, but Windows/Linux do. * but it remains standard practice for Windows and Linux environments.
*/ */
tray.on("click", () => { tray.on("click", () => {
if (mainWindow.isVisible()) { if (mainWindow.isVisible()) {

View File

@@ -131,7 +131,7 @@ app.whenReady().then(async () => {
getMainWindow().show(); getMainWindow().show();
if (configFeatures.systemTray) { if (configFeatures.systemTray) {
createSystemTray(getMainWindow()); createSystemTray(getMainWindow(), config.devMode);
} }
if (configFeatures.discordRPC) startRPC(); if (configFeatures.discordRPC) startRPC();

View File

@@ -84,6 +84,14 @@
"from": "theme", "from": "theme",
"to": "theme" "to": "theme"
}, },
{
"from": "build/app-icon.ico",
"to": "app-icon.ico"
},
{
"from": "build/app-icon-64x64.png",
"to": "app-icon-64x64.png"
},
{ {
"from": "build/confirm-icon.png", "from": "build/confirm-icon.png",
"to": "confirm-icon.png" "to": "confirm-icon.png"