From fc53f978b665d689e5ef10da57bbcdeb29f2c3d6 Mon Sep 17 00:00:00 2001 From: Pim de Jong <22365764+P-de-Jong@users.noreply.github.com> Date: Sun, 12 Apr 2026 10:18:41 +0200 Subject: [PATCH] [codex] Guard traffic light sync off macOS (#531) --- src/main/window/createMainWindow.test.ts | 51 ++++++++++++++++++++++++ src/main/window/createMainWindow.ts | 2 +- src/renderer/src/lib/ui-zoom.ts | 10 ++++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main/window/createMainWindow.test.ts b/src/main/window/createMainWindow.test.ts index 811b68983be..48092db7a47 100644 --- a/src/main/window/createMainWindow.test.ts +++ b/src/main/window/createMainWindow.test.ts @@ -34,6 +34,7 @@ vi.mock('../browser/browser-manager', () => ({ })) import { createMainWindow } from './createMainWindow' +import { ipcMain } from 'electron' describe('createMainWindow', () => { beforeEach(() => { @@ -41,6 +42,8 @@ describe('createMainWindow', () => { openExternalMock.mockReset() attachGuestPoliciesMock.mockReset() isMock.dev = false + vi.mocked(ipcMain.on).mockReset() + vi.mocked(ipcMain.removeListener).mockReset() }) it('enables renderer sandboxing and opens external links safely', () => { @@ -436,4 +439,52 @@ describe('createMainWindow', () => { windowHandlers['will-prevent-unload']() expect(onQuitAborted).toHaveBeenCalledTimes(1) }) + + it('ignores traffic light sync IPC on non-macOS', () => { + const windowHandlers: Record void> = {} + const webContents = { + on: vi.fn((event, handler) => { + windowHandlers[event] = handler + }), + setZoomLevel: vi.fn(), + setBackgroundThrottling: vi.fn(), + invalidate: vi.fn(), + setWindowOpenHandler: vi.fn(), + send: vi.fn() + } + const browserWindowInstance = { + webContents, + on: vi.fn(), + isDestroyed: vi.fn(() => false), + isMaximized: vi.fn(() => true), + isFullScreen: vi.fn(() => false), + getSize: vi.fn(() => [1200, 800]), + setSize: vi.fn(), + setWindowButtonPosition: vi.fn(), + maximize: vi.fn(), + show: vi.fn(), + loadFile: vi.fn(), + loadURL: vi.fn() + } + browserWindowMock.mockImplementation(function () { + return browserWindowInstance + }) + + createMainWindow(null) + + const syncListener = vi + .mocked(ipcMain.on) + .mock.calls.find(([channel]) => channel === 'ui:sync-traffic-lights')?.[1] + + expect(syncListener).toBeTypeOf('function') + + syncListener?.({} as never, 1.2) + + if (process.platform === 'darwin') { + expect(browserWindowInstance.setWindowButtonPosition).toHaveBeenCalledWith({ x: 16, y: 18 }) + return + } + + expect(browserWindowInstance.setWindowButtonPosition).not.toHaveBeenCalled() + }) }) diff --git a/src/main/window/createMainWindow.ts b/src/main/window/createMainWindow.ts index 6d7c604f13c..2c9de1c647c 100644 --- a/src/main/window/createMainWindow.ts +++ b/src/main/window/createMainWindow.ts @@ -38,7 +38,7 @@ const TRAFFIC_LIGHT_RADIUS = 6 const TRAFFIC_LIGHT_X = 16 function syncTrafficLightPosition(win: BrowserWindow, zoomFactor: number): void { - if (win.isDestroyed()) { + if (process.platform !== 'darwin' || win.isDestroyed()) { return } const y = Math.round(TITLEBAR_CSS_CENTER * zoomFactor - TRAFFIC_LIGHT_RADIUS) diff --git a/src/renderer/src/lib/ui-zoom.ts b/src/renderer/src/lib/ui-zoom.ts index 12d3aa0ccb5..7ab1a00e19f 100644 --- a/src/renderer/src/lib/ui-zoom.ts +++ b/src/renderer/src/lib/ui-zoom.ts @@ -1,3 +1,5 @@ +const isMac = navigator.userAgent.includes('Mac') + /** * Apply a UI zoom level change: sets webFrame zoom via the preload API, * updates the CSS variable used to compensate the traffic-light pad, @@ -7,7 +9,9 @@ export function applyUIZoom(level: number): void { const zoomFactor = Math.pow(1.2, level) window.api.ui.setZoomLevel(level) document.documentElement.style.setProperty('--ui-zoom-factor', String(zoomFactor)) - window.api.ui.syncTrafficLights(zoomFactor) + if (isMac) { + window.api.ui.syncTrafficLights(zoomFactor) + } } /** @@ -18,5 +22,7 @@ export function syncZoomCSSVar(): void { const level = window.api.ui.getZoomLevel() const zoomFactor = Math.pow(1.2, level) document.documentElement.style.setProperty('--ui-zoom-factor', String(zoomFactor)) - window.api.ui.syncTrafficLights(zoomFactor) + if (isMac) { + window.api.ui.syncTrafficLights(zoomFactor) + } }