Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): avoid duplicate tray icon on linux by updating context menu in-place (#466)

Aly Yasser Pranajaya6180a68a745d
diff --git a/apps/desktop/src/main/desktop-update-flow.test.mjs b/apps/desktop/src/main/desktop-update-flow.test.mjs
index b8bc9d09..26cb9de3 100644
--- a/apps/desktop/src/main/desktop-update-flow.test.mjs
+++ b/apps/desktop/src/main/desktop-update-flow.test.mjs
@@ -91,4 +91,9 @@ describe("desktop update flow", () => {
expect(systemInfoSource).toContain("clientAheadOfInstanceByPlatform");
expect(systemInfoSource).toContain("isClientAheadOfInstance");
});
+
+ test("updates the existing tray context menu in-place without destroying the tray instance", () => {
+ expect(mainSource).not.toContain("tray.destroy();\n createTray();");
+ expect(mainSource).toContain("tray.setContextMenu(buildTrayContextMenu())");
+ });
});
diff --git a/apps/desktop/src/main/index.mjs b/apps/desktop/src/main/index.mjs
index bf03f757..99c35d2a 100644
--- a/apps/desktop/src/main/index.mjs
+++ b/apps/desktop/src/main/index.mjs
@@ -782,8 +782,22 @@ const buildApplicationMenu = () => {
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
};
-const createTray = () => {
+const buildTrayContextMenu = () => {
const copy = desktopMenuCopy(app.getLocale());
+ return Menu.buildFromTemplate([
+ { label: copy.show, click: () => showWindow(mainWindow) },
+ { label: copy.screenshotToNote, click: () => void captureScreenshotToNote() },
+ ...(updateState === "downloaded" ? [{ label: copy.restartToUpdate, click: () => installDownloadedUpdate() }] : []),
+ { type: "separator" },
+ { label: copy.quit, click: () => { isQuitting = true; app.quit(); } },
+ ]);
+};
+
+const createTray = () => {
+ if (tray && !tray.isDestroyed?.()) {
+ tray.setContextMenu(buildTrayContextMenu());
+ return;
+ }
const iconPath = trayIconPath({
isPackaged: app.isPackaged,
platform: process.platform,
@@ -794,13 +808,7 @@ const createTray = () => {
if (process.platform === "darwin") icon.setTemplateImage(true);
tray = new Tray(icon);
tray.setToolTip("EdgeEver");
- tray.setContextMenu(Menu.buildFromTemplate([
- { label: copy.show, click: () => showWindow(mainWindow) },
- { label: copy.screenshotToNote, click: () => void captureScreenshotToNote() },
- ...(updateState === "downloaded" ? [{ label: copy.restartToUpdate, click: () => installDownloadedUpdate() }] : []),
- { type: "separator" },
- { label: copy.quit, click: () => { isQuitting = true; app.quit(); } },
- ]));
+ tray.setContextMenu(buildTrayContextMenu());
tray.on("double-click", () => showWindow(mainWindow));
};
@@ -999,9 +1007,12 @@ const preparePackagedRendererOrigin = async () => {
};
const refreshTrayMenu = () => {
- if (!tray) return;
- tray.destroy();
- createTray();
+ if (isQuitting) return;
+ if (!tray || tray.isDestroyed?.()) {
+ createTray();
+ return;
+ }
+ tray.setContextMenu(buildTrayContextMenu());
};
const desktopUpdateStatus = () => ({