Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(desktop): tray double-click opens main window (#15816)

Innei536290973bba
diff --git a/apps/desktop/src/main/core/ui/Tray.ts b/apps/desktop/src/main/core/ui/Tray.ts
index 30c6e642186..f827be25b87 100644
--- a/apps/desktop/src/main/core/ui/Tray.ts
+++ b/apps/desktop/src/main/core/ui/Tray.ts
@@ -16,6 +16,12 @@ import type { App } from '../App';
// Create logger
const logger = createLogger('core:Tray');
+// Debounce window for distinguishing a single-click from the leading edge of
+// a double-click. Electron delivers two `click` events before `double-click`,
+// so we defer the single-click action until this window passes — the
+// `double-click` handler clears it if it arrives in time.
+const CLICK_DEBOUNCE_MS = 250;
+
export interface TrayOptions {
/**
* Tray icon path (relative to resource directory)
@@ -54,6 +60,12 @@ export class Tray {
*/
private _contextMenu?: ElectronMenu;
+ /**
+ * Pending single-click timer. Cleared by the double-click handler so a
+ * double-click never accidentally fires startSession before showMainWindow.
+ */
+ private _clickTimer?: NodeJS.Timeout;
+
/**
* Identifier
*/
@@ -118,10 +130,25 @@ export class Tray {
// Set default context menu
this.setContextMenu();
- // Left-click: open Quick Composer.
+ // Left-click: deferred so a follow-up `double-click` can pre-empt it.
this._tray.on('click', () => {
logger.debug(`[${this.identifier}] Tray clicked`);
- this.onClick();
+ if (this._clickTimer) clearTimeout(this._clickTimer);
+ this._clickTimer = setTimeout(() => {
+ this._clickTimer = undefined;
+ this.onClick();
+ }, CLICK_DEBOUNCE_MS);
+ });
+
+ // Double-click (macOS / Windows): cancel the pending single-click and
+ // surface the main window instead.
+ this._tray.on('double-click', () => {
+ logger.debug(`[${this.identifier}] Tray double-clicked`);
+ if (this._clickTimer) {
+ clearTimeout(this._clickTimer);
+ this._clickTimer = undefined;
+ }
+ this.onDoubleClick();
});
// Right-click: pop the stored context menu manually so left-click stays
@@ -189,6 +216,18 @@ export class Tray {
}
}
+ /**
+ * Handle tray double-click event — surfaces the main window.
+ */
+ onDoubleClick() {
+ logger.debug(`[${this.identifier}] Tray double-click → showMainWindow`);
+ try {
+ this.app.browserManager.showMainWindow();
+ } catch (error) {
+ logger.error(`[${this.identifier}] Failed to show main window:`, error);
+ }
+ }
+
/**
* Replace the tray context menu with a pre-built Electron Menu instance.
* Stored in-house and popped up manually on right-click to preserve
@@ -259,6 +298,10 @@ export class Tray {
*/
destroy() {
logger.debug(`Destroying tray instance: ${this.identifier}`);
+ if (this._clickTimer) {
+ clearTimeout(this._clickTimer);
+ this._clickTimer = undefined;
+ }
if (this._tray) {
this._tray.destroy();
this._tray = undefined;
diff --git a/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts b/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts
index f73c10856f6..c95ad61a4d0 100644
--- a/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts
+++ b/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts
@@ -189,7 +189,7 @@ describe('Tray', () => {
expect(mockElectronTray.setContextMenu).not.toHaveBeenCalled();
});
- it('should register both click and right-click listeners', () => {
+ it('should register click, double-click and right-click listeners', () => {
tray = new Tray(
{
iconPath: 'tray.png',
@@ -200,6 +200,7 @@ describe('Tray', () => {
const events = mockElectronTray.on.mock.calls.map((c: any[]) => c[0]);
expect(events).toContain('click');
+ expect(events).toContain('double-click');
expect(events).toContain('right-click');
});
@@ -346,6 +347,96 @@ describe('Tray', () => {
});
});
+ describe('onDoubleClick', () => {
+ beforeEach(() => {
+ tray = new Tray(
+ {
+ iconPath: 'tray.png',
+ identifier: 'test-tray',
+ },
+ mockApp,
+ );
+ });
+
+ it('should show the main window', () => {
+ tray.onDoubleClick();
+
+ expect(mockApp.browserManager.showMainWindow).toHaveBeenCalled();
+ });
+
+ it('should not start the capture session', () => {
+ tray.onDoubleClick();
+
+ expect(mockApp.screenCaptureManager.startSession).not.toHaveBeenCalled();
+ });
+
+ it('should not throw when showMainWindow throws', () => {
+ vi.mocked(mockApp.browserManager.showMainWindow).mockImplementationOnce(() => {
+ throw new Error('window failed');
+ });
+
+ expect(() => tray.onDoubleClick()).not.toThrow();
+ });
+ });
+
+ describe('click vs double-click handling', () => {
+ let clickHandler: (() => void) | undefined;
+ let doubleClickHandler: (() => void) | undefined;
+
+ beforeEach(() => {
+ vi.useFakeTimers();
+ tray = new Tray(
+ {
+ iconPath: 'tray.png',
+ identifier: 'test-tray',
+ },
+ mockApp,
+ );
+
+ clickHandler = mockElectronTray.on.mock.calls.find((c: any[]) => c[0] === 'click')?.[1];
+ doubleClickHandler = mockElectronTray.on.mock.calls.find(
+ (c: any[]) => c[0] === 'double-click',
+ )?.[1];
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('should debounce single click before calling startSession', () => {
+ expect(clickHandler).toBeDefined();
+
+ clickHandler?.();
+ expect(mockApp.screenCaptureManager.startSession).not.toHaveBeenCalled();
+
+ vi.advanceTimersByTime(250);
+ expect(mockApp.screenCaptureManager.startSession).toHaveBeenCalledTimes(1);
+ });
+
+ it('should cancel the pending single click when double-click fires', () => {
+ expect(clickHandler).toBeDefined();
+ expect(doubleClickHandler).toBeDefined();
+
+ clickHandler?.();
+ clickHandler?.();
+ doubleClickHandler?.();
+
+ vi.advanceTimersByTime(1000);
+
+ expect(mockApp.screenCaptureManager.startSession).not.toHaveBeenCalled();
+ expect(mockApp.browserManager.showMainWindow).toHaveBeenCalledTimes(1);
+ });
+
+ it('should only fire startSession once per single-click burst', () => {
+ clickHandler?.();
+ clickHandler?.();
+
+ vi.advanceTimersByTime(250);
+
+ expect(mockApp.screenCaptureManager.startSession).toHaveBeenCalledTimes(1);
+ });
+ });
+
describe('updateIcon', () => {
beforeEach(() => {
tray = new Tray(