mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
fix(desktop): publish native menu zoom changes (#46773)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
setDockIcon,
|
||||
setPinchZoomEnabled,
|
||||
setTitlebar,
|
||||
setZoomFactor,
|
||||
updateTitlebar,
|
||||
windowAppearance,
|
||||
wireFullscreen,
|
||||
@@ -44,6 +45,7 @@ export {
|
||||
setDockIcon,
|
||||
setPinchZoomEnabled,
|
||||
setTitlebar,
|
||||
setZoomFactor,
|
||||
updateTitlebar,
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user