diff --git a/app/electron/main.ts b/app/electron/main.ts index 4b1e0a1ac5..2fd83882f0 100644 --- a/app/electron/main.ts +++ b/app/electron/main.ts @@ -767,18 +767,21 @@ function getDefaultAppMenu(): AppMenu[] { sep, { label: i18n.t('Reset Zoom'), - role: 'resetzoom', id: 'original-reset-zoom', + accelerator: 'CmdOrCtrl+0', + click: () => saveZoomFactor(1.0), }, { label: i18n.t('Zoom In'), - role: 'zoomin', id: 'original-zoom-in', + accelerator: 'CmdOrCtrl+Plus', + click: () => adjustZoom(0.1), }, { label: i18n.t('Zoom Out'), - role: 'zoomout', id: 'original-zoom-out', + accelerator: 'CmdOrCtrl+-', + click: () => adjustZoom(-0.1), }, sep, { @@ -1014,6 +1017,37 @@ function killProcess(pid: number) { } } +const ZOOM_FILE_PATH = path.join(app.getPath('userData'), 'zoomconfig.json'); + +function saveZoomFactor(factor: number) { + try { + fs.writeFileSync(ZOOM_FILE_PATH, JSON.stringify({ zoomFactor: factor }), 'utf-8'); + } catch (err) { + console.error(`Failed to save zoom factor:`, err); + } +} + +function loadZoomFactor(): number { + try { + const { zoomFactor = 1.0 } = JSON.parse(fs.readFileSync(ZOOM_FILE_PATH, 'utf-8')); + return typeof zoomFactor === 'number' ? zoomFactor : 1.0; + } catch { + // If the file doesn’t exist or JSON is invalid, fall back to 1.0 + return 1.0; + } +} + +function adjustZoom(delta: number) { + if (!mainWindow) { + return; + } + + const current = mainWindow.webContents.getZoomFactor(); + const next = Math.min(5.0, Math.max(0.25, current + delta)); + mainWindow.webContents.setZoomFactor(next); + saveZoomFactor(next); +} + function startElecron() { console.info('App starting...'); @@ -1067,6 +1101,11 @@ function startElecron() { } }); + mainWindow.webContents.on('did-finish-load', () => { + const savedZoomFactor = loadZoomFactor(); + mainWindow?.webContents.setZoomFactor(savedZoomFactor); + }); + mainWindow.webContents.on('dom-ready', () => { const defaultMenu = getDefaultAppMenu(); const currentMenu = JSON.parse(JSON.stringify(defaultMenu));