fix(desktop): publish native menu zoom changes (#46773)

This commit is contained in:
Luke Parker 2026-09-02 19:07:12 +10:00 committed by GitHub
parent c2a7616beb
commit eead95e712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 10 deletions

View file

@ -1,6 +1,6 @@
import { BrowserWindow } from "electron"
import type { DesktopMenuAction } from "@opencode-ai/app/desktop-menu"
import { updateTitlebar } from "../windows"
import { setZoomFactor } from "../windows"
export type DesktopMenuActionHandlers = Partial<{
checkForUpdates: () => void
@ -47,13 +47,13 @@ export function runDesktopMenuAction(
win?.webContents.toggleDevTools()
return
case "view.resetZoom":
setZoom(win, 1)
if (win) setZoomFactor(win, 1)
return
case "view.zoomIn":
setZoom(win, (win?.webContents.getZoomFactor() ?? 1) + 0.2)
if (win) setZoomFactor(win, win.webContents.getZoomFactor() + 0.2)
return
case "view.zoomOut":
setZoom(win, (win?.webContents.getZoomFactor() ?? 1) - 0.2)
if (win) setZoomFactor(win, win.webContents.getZoomFactor() - 0.2)
return
case "view.toggleFullscreen":
win?.setFullScreen(!win.isFullScreen())
@ -81,9 +81,3 @@ export function runDesktopMenuAction(
return
}
}
function setZoom(win: BrowserWindow | null, value: number) {
if (!win) return
win.webContents.setZoomFactor(Math.min(Math.max(value, 0.2), 10))
updateTitlebar(win)
}

View file

@ -99,6 +99,11 @@ export function getPinchZoomEnabled() {
return getStore().get(PINCH_ZOOM_ENABLED_KEY) === true
}
export function setZoomFactor(win: BrowserWindow, factor: number) {
win.webContents.setZoomFactor(clampZoom(factor))
updateZoom(win)
}
export function wireZoom(win: BrowserWindow) {
pinchZoomEnabled.set(win, getPinchZoomEnabled())
win.webContents.setZoomFactor(1)

View file

@ -15,6 +15,7 @@ import {
setDockIcon,
setPinchZoomEnabled,
setTitlebar,
setZoomFactor,
updateTitlebar,
windowAppearance,
wireFullscreen,
@ -44,6 +45,7 @@ export {
setDockIcon,
setPinchZoomEnabled,
setTitlebar,
setZoomFactor,
updateTitlebar,
}

View file

@ -46,6 +46,13 @@ const applyZoom = (next: number) => {
})
}
// A renderer reload keeps the window's zoom, so seed the signal from main.
void api.getZoomFactor().then((factor) => {
if (requestedZoom !== 1) return
requestedZoom = clamp(factor)
setWebviewZoom(requestedZoom)
})
api.onZoomFactorChanged((factor) => {
requestedZoom = clamp(factor)
setWebviewZoom(requestedZoom)