From 71bbec7084ca1583c7d785a8d0d64ee61991fb56 Mon Sep 17 00:00:00 2001 From: LukeGus Date: Wed, 30 Sep 2026 12:15:35 -0500 Subject: [PATCH] fix: load the linux tray icon reliably and log tray failures (#1332) --- electron/main.cjs | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/electron/main.cjs b/electron/main.cjs index 69dfb549d..01e53fb0d 100644 --- a/electron/main.cjs +++ b/electron/main.cjs @@ -1310,7 +1310,16 @@ function createTray() { } else if (process.platform === "win32") { trayIcon = path.join(publicRoot, "icon.ico"); } else { - trayIcon = path.join(publicRoot, "icons", "32x32.png"); + trayIcon = loadLinuxTrayIcon(nativeImage, publicRoot); + if (!trayIcon) { + logToFile("Tray icon not found, skipping the system tray"); + return; + } + if (/gnome/i.test(process.env.XDG_CURRENT_DESKTOP || "")) { + logToFile( + "GNOME shows tray icons only with the AppIndicator extension installed", + ); + } } tray = new Tray(trayIcon); @@ -1348,12 +1357,29 @@ function createTray() { } }); - console.log("System tray created successfully"); + logToFile("System tray created"); } catch (err) { - console.error("Failed to create system tray:", err); + tray = null; + logToFile("Failed to create system tray:", err?.message || String(err)); } } +function loadLinuxTrayIcon(nativeImage, publicRoot) { + const roots = [ + publicRoot, + path.join(process.resourcesPath || "", "app.asar.unpacked", "public"), + ]; + for (const root of roots) { + for (const size of ["32x32", "24x24", "48x48"]) { + const image = nativeImage.createFromPath( + path.join(root, "icons", `${size}.png`), + ); + if (!image.isEmpty()) return image; + } + } + return null; +} + function createWindow() { const appVersion = app.getVersion(); const electronVersion = process.versions.electron; @@ -1555,7 +1581,15 @@ function createWindow() { mainWindow.on("close", (event) => { if (!isQuitting && tray && !tray.isDestroyed()) { event.preventDefault(); - mainWindow.hide(); + // Stock GNOME has no tray to bring a hidden window back from. + if ( + process.platform === "linux" && + /gnome/i.test(process.env.XDG_CURRENT_DESKTOP || "") + ) { + mainWindow.minimize(); + } else { + mainWindow.hide(); + } } });