Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(desktop): on Linux the lending indicator borrows the one tray icon instead of making a second one
Kanzal Qalandrid06f8cc356bb
diff --git a/electron/main.mjs b/electron/main.mjsindex ed2a0019a3..6d5fbd4124 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -1482,9 +1482,11 @@ const lendingActivity = createActivityWindow({ BrowserWindow, icon: APP_ICON, balet lendingTray = null;function lendingIndicator() {lendingTray ??= createLendingIndicator({- Tray, Menu, nativeImage, Notification, iconPath: APP_ICON, t: nativeT, onPause: () => sharingController().pause(), onActivity: () => lendingActivity.show(),+ // On Linux the lending indicator borrows the one tray icon: a second one would be a GtkStatusIcon nobody sees.+ Tray: linuxTray ? class { constructor() { return linuxTray.borrow(); } } : Tray,+ Menu, nativeImage, Notification, iconPath: APP_ICON, t: nativeT, onPause: () => sharingController().pause(), onActivity: () => lendingActivity.show(),onResume: () => void sharingController().resume()?.catch(error => slog(`lending resume: ${error?.message ?? error}`)), onStartScreen: () => void screenControl.start(),- onTerminal: on => void lendingDialogs.lendTerminal(on, () => sharingController().lendTerminal(on)).catch(error => slog(`lending terminal: ${error?.message ?? error}`)), onQuit: process.platform === "win32" ? () => app.quit() : null,+ onTerminal: on => void lendingDialogs.lendTerminal(on, () => sharingController().lendTerminal(on)).catch(error => slog(`lending terminal: ${error?.message ?? error}`)), onQuit: process.platform === "win32" || linuxTray ? () => app.quit() : null,});return lendingTray;}diff --git a/electron/startup-tray.node-test.mjs b/electron/startup-tray.node-test.mjsindex 4f7af32437..f32c315665 100644--- a/electron/startup-tray.node-test.mjs+++ b/electron/startup-tray.node-test.mjs@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";import test from "node:test";import nativeText from "./native-text.cjs";import { createStartupScreen, startupScreenHtml } from "./startup-screen.mjs";+import { createLendingIndicator } from "./lending-indicator.mjs";import { createSystemTray } from "./system-tray.mjs";const iconPath = fileURLToPath(new URL("./resources/app-icon.png", import.meta.url));@@ -241,3 +242,43 @@ test("the startup screen says how the workspace came up, once", async t => {hidden.win.webContents.emit("did-finish-load"); await flush();assert.equal(ways.at(-1), "hidden");});++test("on Linux the lending indicator borrows the one tray icon and hands Open and Quit back", () => {+ const made = [], opened = [];+ class Tray extends EventEmitter {+ constructor() { super(); made.push(this); }+ setToolTip(value) { this.tooltip = value; }+ setTitle(value) { this.title = value; }+ setContextMenu(value) { this.menu = value; }+ isDestroyed() { return this.destroyed ?? false; }+ destroy() { this.destroyed = true; }+ }+ const fakes = { Menu: { buildFromTemplate: value => value }, nativeImage: { createFromPath: () => ({ resize: () => ({}) }) }, iconPath };+ const win = new Window();+ const tray = createSystemTray({ ...fakes, Tray, getWindow: () => win, onQuit: () => {} });+ const labels = () => made[0].menu.filter(item => item.label).map(item => item.label);+ const openQuit = labels();+ const lending = createLendingIndicator({ ...fakes, Tray: class { constructor() { return tray.borrow(); } },+ onPause: () => {}, onResume: () => {}, onActivity: () => {}, device: "PC" });+ win.on("show", () => opened.push("show"));++ lending.update({ clouds: ["My Cloud"], using: [], paused: false });+ assert.equal(made.length, 1, "no second tray icon");+ assert.match(made[0].tooltip, /^OpenMausBot: My Cloud/);+ assert.ok(labels().includes("Pause"));+ tray.relabel();+ assert.ok(labels().includes("Pause"), "a language change does not put Open and Quit over the lending menu");+ made[0].emit("click");+ assert.deepEqual(opened, ["show"], "a click still opens the window");++ lending.update({ clouds: [], using: [], paused: false });+ assert.equal(made[0].isDestroyed(), false);+ assert.equal(made[0].tooltip, "OpenMausBot");+ assert.deepEqual(labels(), openQuit);++ lending.update({ clouds: ["My Cloud"], using: [], paused: false });+ assert.equal(made.length, 1);+ assert.ok(labels().includes("Pause"), "lending again borrows the icon again");+ lending.destroy(); tray.destroy();+ assert.equal(made[0].isDestroyed(), true);+});diff --git a/electron/system-tray.mjs b/electron/system-tray.mjsindex 3747e481f0..63f98c0011 100644--- a/electron/system-tray.mjs+++ b/electron/system-tray.mjs@@ -4,7 +4,7 @@ import nativeText from "./native-text.cjs";export function createSystemTray({ Tray, Menu, nativeImage, iconPath, getWindow, onQuit, t = nativeText.englishText.t }) {const tray = new Tray(nativeImage.createFromPath(iconPath).resize({ width: 20, height: 20 }),"889af657-21b5-4ec9-b5d0-cb798cbdfd30");- let hidden = false;+ let hidden = false, lent = false;const show = () => {const win = getWindow();if (!win || win.isDestroyed()) return false;@@ -15,7 +15,7 @@ export function createSystemTray({ Tray, Menu, nativeImage, iconPath, getWindow,win.focus();return true;};- const label = () => tray.setContextMenu(Menu.buildFromTemplate([+ const label = () => lent || tray.setContextMenu(Menu.buildFromTemplate([{ label: t("native.tray.open"), click: show },{ type: "separator" },{ label: t("native.tray.quit"), click: onQuit },@@ -30,6 +30,30 @@ export function createSystemTray({ Tray, Menu, nativeImage, iconPath, getWindow,isHidden() { return hidden; },windowShown(win) { hidden = false; win.setSkipTaskbar(false); },relabel() { if (!tray.isDestroyed()) label(); },+ /**+ * Linux gives StatusNotifierItem to the first tray only; a second one falls back to GtkStatusIcon, which GNOME and+ * KDE on Wayland never show. So the lending indicator borrows this icon while it has something to say, and its+ * destroy() hands the icon back with Open and Quit. Clicks stay this tray's: they open the window.+ */+ borrow() {+ lent = true;+ let returned = false;+ return {+ setToolTip: value => tray.setToolTip(value),+ setTitle: value => tray.setTitle?.(value),+ setContextMenu: menu => tray.setContextMenu(menu),+ popUpContextMenu: () => tray.popUpContextMenu?.(),+ on() {},+ isDestroyed: () => returned || tray.isDestroyed(),+ destroy() {+ if (returned) return;+ returned = true; lent = false;+ if (tray.isDestroyed()) return;+ tray.setToolTip("OpenMausBot");+ label();+ },+ };+ },destroy() { if (!tray.isDestroyed()) tray.destroy(); },};}