From a33d708e069c59bc52f6fc76c2e0291e27280c66 Mon Sep 17 00:00:00 2001 From: plebeius Date: Fri, 26 Sep 2025 22:08:52 +0200 Subject: [PATCH] fix(electron): keep module-scoped Tray ref and destroy before reassign --- electron/main.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/electron/main.js b/electron/main.js index 39755ec7..def40922 100644 --- a/electron/main.js +++ b/electron/main.js @@ -38,6 +38,9 @@ if (isLinux && !process.env.SEEDIT_NO_ENV_SANITIZE) { delete process.env.LD_PRELOAD; } +// Keep a global Tray reference to prevent GC removing the tray icon +let tray; + // Determine __filename and dirname for ESM const __filename = fileURLToPath(import.meta.url); const dirname = path.dirname(__filename); @@ -346,7 +349,12 @@ const createMainWindow = () => { if (!trayDisabled) { // tray const trayIconPath = path.join(dirname, '..', isDev ? 'public' : 'build', 'electron-tray-icon.png'); - const tray = new Tray(trayIconPath); + if (tray) { + try { + tray.destroy(); + } catch (e) {} + } + tray = new Tray(trayIconPath); tray.setToolTip('seedit'); const trayMenu = Menu.buildFromTemplate([ {