From 72417fb7b9fd0265e1be517dcad83819a88b81c6 Mon Sep 17 00:00:00 2001 From: Owen McGirr Date: Sat, 20 Jun 2026 19:53:28 +0100 Subject: [PATCH] Fix tray context menu --- src/main/tray.test.ts | 18 +++++++++--------- src/main/tray.ts | 12 +----------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/tray.test.ts b/src/main/tray.test.ts index c56cf7b..1838f72 100644 --- a/src/main/tray.test.ts +++ b/src/main/tray.test.ts @@ -98,33 +98,33 @@ describe('createSwitchifyTray', () => { expect(callbacks.quit).not.toHaveBeenCalled(); }); - it('opens the context menu on Windows right-click', () => { + it('attaches the context menu on Windows', () => { const callbacks = createCallbacks(); createSwitchifyTray({ ...callbacks, getStatus: () => status() }); - tray().emit('right-click'); - - expect(tray().popUpContextMenu).toHaveBeenCalledTimes(1); - expect(tray().popUpContextMenu).toHaveBeenCalledWith(lastMenu()); - expect(callbacks.showWindow).not.toHaveBeenCalled(); + expect(tray().setContextMenu).toHaveBeenCalledTimes(1); + expect(tray().setContextMenu).toHaveBeenCalledWith(lastMenu()); + expect(tray().popUpContextMenu).not.toHaveBeenCalled(); + expect(tray().handlers.has('right-click')).toBe(false); }); - it('refreshes the right-click menu with the latest status', () => { + it('refreshes the context menu with the latest status on update', () => { const callbacks = createCallbacks(); let connectedClientCount = 0; - createSwitchifyTray({ + const switchifyTray = createSwitchifyTray({ ...callbacks, getStatus: () => status({ connectedClientCount }) }); connectedClientCount = 1; - tray().emit('right-click'); + switchifyTray.update(); const disconnectItem = lastMenu().template.find((item) => item.label === 'Disconnect device'); expect(disconnectItem?.enabled).toBe(true); + expect(tray().setContextMenu).toHaveBeenLastCalledWith(lastMenu()); }); it('refreshes the tooltip on update', () => { diff --git a/src/main/tray.ts b/src/main/tray.ts index 9928dca..5e4067c 100644 --- a/src/main/tray.ts +++ b/src/main/tray.ts @@ -24,20 +24,10 @@ export function createSwitchifyTray(options: SwitchifyTrayOptions): SwitchifyTra const status = options.getStatus(); currentMenu = buildTrayMenu(options, status); tray.setToolTip(`Switchify PC - ${formatTooltipStatus(status)}`); - if (process.platform !== 'win32') { - tray.setContextMenu(currentMenu); - } + tray.setContextMenu(currentMenu); }; tray.on('click', options.showWindow); - if (process.platform === 'win32') { - tray.on('right-click', () => { - update(); - if (currentMenu) { - tray.popUpContextMenu(currentMenu); - } - }); - } update(); return {