[codex] Guard traffic light sync off macOS (#531)

This commit is contained in:
Pim de Jong
2026-04-12 01:18:41 -07:00
committed by GitHub
parent 839d87181b
commit fc53f978b6
3 changed files with 60 additions and 3 deletions
+51
View File
@@ -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<string, (...args: any[]) => 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()
})
})
+1 -1
View File
@@ -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)
+8 -2
View File
@@ -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)
}
}