Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/desktop/src/main/native/menu-actions.ts
Original file line number Diff line number Diff line change
@@ -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"
Comment on lines 1 to +3

export type DesktopMenuActionHandlers = Partial<{
checkForUpdates: () => void
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions packages/desktop/src/main/windows/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop/src/main/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
setDockIcon,
setPinchZoomEnabled,
setTitlebar,
setZoomFactor,
updateTitlebar,
windowAppearance,
wireFullscreen,
Expand Down Expand Up @@ -44,6 +45,7 @@ export {
setDockIcon,
setPinchZoomEnabled,
setTitlebar,
setZoomFactor,
updateTitlebar,
}

Expand Down
7 changes: 7 additions & 0 deletions packages/desktop/src/renderer/window/zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Comment on lines +49 to +54

api.onZoomFactorChanged((factor) => {
requestedZoom = clamp(factor)
setWebviewZoom(requestedZoom)
Expand Down
Loading