From 518b86b4106835db82caf569cfa16ce0703c9b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gl=C3=BCck?= Date: Wed, 13 Aug 2025 19:57:17 +0200 Subject: [PATCH] Add possibility to set a zoom factor to window API This commit allows to define a zoom factor for new and existing windows. The zoom factor is the zoom percent divided by 100, so 150% = 1.5. --- .../js/electron-plugin/dist/server/api/window.js | 11 ++++++++++- .../js/electron-plugin/src/server/api/window.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/dist/server/api/window.js b/resources/js/electron-plugin/dist/server/api/window.js index 9e1e0a2e..ada480ea 100644 --- a/resources/js/electron-plugin/dist/server/api/window.js +++ b/resources/js/electron-plugin/dist/server/api/window.js @@ -53,6 +53,12 @@ router.post('/hide-dev-tools', (req, res) => { (_a = state.windows[id]) === null || _a === void 0 ? void 0 : _a.webContents.closeDevTools(); res.sendStatus(200); }); +router.post('/set-zoom-factor', (req, res) => { + var _a; + const { id, zoomFactor } = req.body; + (_a = state.windows[id]) === null || _a === void 0 ? void 0 : _a.webContents.setZoomFactor(parseFloat(zoomFactor)); + res.sendStatus(200); +}); router.post('/position', (req, res) => { var _a; const { id, x, y, animate } = req.body; @@ -139,7 +145,7 @@ function getWindowData(id) { }; } router.post('/open', (req, res) => { - let { id, x, y, frame, width, height, minWidth, minHeight, maxWidth, maxHeight, focusable, skipTaskbar, hiddenInMissionControl, hasShadow, url, resizable, movable, minimizable, maximizable, closable, title, alwaysOnTop, titleBarStyle, trafficLightPosition, vibrancy, backgroundColor, transparency, showDevTools, fullscreen, fullscreenable, kiosk, autoHideMenuBar, webPreferences, } = req.body; + let { id, x, y, frame, width, height, minWidth, minHeight, maxWidth, maxHeight, focusable, skipTaskbar, hiddenInMissionControl, hasShadow, url, resizable, movable, minimizable, maximizable, closable, title, alwaysOnTop, titleBarStyle, trafficLightPosition, vibrancy, backgroundColor, transparency, showDevTools, fullscreen, fullscreenable, kiosk, autoHideMenuBar, webPreferences, zoomFactor, } = req.body; if (state.windows[id]) { state.windows[id].show(); state.windows[id].focus(); @@ -247,6 +253,9 @@ router.post('/open', (req, res) => { }); url = appendWindowIdToUrl(url, id); window.loadURL(url); + window.webContents.on('dom-ready', () => { + window.webContents.setZoomFactor(parseFloat(zoomFactor)); + }); window.webContents.on('did-finish-load', () => { window.show(); }); diff --git a/resources/js/electron-plugin/src/server/api/window.ts b/resources/js/electron-plugin/src/server/api/window.ts index 640e0be1..16eb45c8 100644 --- a/resources/js/electron-plugin/src/server/api/window.ts +++ b/resources/js/electron-plugin/src/server/api/window.ts @@ -73,6 +73,14 @@ router.post('/hide-dev-tools', (req, res) => { res.sendStatus(200); }); +router.post('/set-zoom-factor', (req, res) => { + const {id, zoomFactor} = req.body; + + state.windows[id]?.webContents.setZoomFactor(parseFloat(zoomFactor)); + + res.sendStatus(200); +}); + router.post('/position', (req, res) => { const {id, x, y, animate} = req.body; @@ -225,6 +233,7 @@ router.post('/open', (req, res) => { kiosk, autoHideMenuBar, webPreferences, + zoomFactor, } = req.body; if (state.windows[id]) { @@ -377,6 +386,10 @@ router.post('/open', (req, res) => { window.loadURL(url); + window.webContents.on('dom-ready', () => { + window.webContents.setZoomFactor(parseFloat(zoomFactor)); + }); + window.webContents.on('did-finish-load', () => { window.show(); });