From 6d3f969c498631373d8d2ee514facd16f651c13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gl=C3=BCck?= Date: Fri, 22 Aug 2025 13:19:05 +0200 Subject: [PATCH] Optionally prevent opening of sub-windows --- resources/js/electron-plugin/dist/server/api/window.js | 7 ++++++- resources/js/electron-plugin/src/server/api/window.ts | 7 +++++++ 2 files changed, 13 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 ada480ea..a5b60fa0 100644 --- a/resources/js/electron-plugin/dist/server/api/window.js +++ b/resources/js/electron-plugin/dist/server/api/window.js @@ -145,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, zoomFactor, } = 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, suppressNewWindows, } = req.body; if (state.windows[id]) { state.windows[id].show(); state.windows[id].focus(); @@ -197,6 +197,11 @@ router.post('/open', (req, res) => { if (req.body.rememberState === true) { windowState === null || windowState === void 0 ? void 0 : windowState.manage(window); } + if (suppressNewWindows) { + window.webContents.setWindowOpenHandler(() => { + return { action: "deny" }; + }); + } window.on('blur', () => { notifyLaravel('events', { event: 'Native\\Laravel\\Events\\Windows\\WindowBlurred', diff --git a/resources/js/electron-plugin/src/server/api/window.ts b/resources/js/electron-plugin/src/server/api/window.ts index 16eb45c8..a68c8f6d 100644 --- a/resources/js/electron-plugin/src/server/api/window.ts +++ b/resources/js/electron-plugin/src/server/api/window.ts @@ -234,6 +234,7 @@ router.post('/open', (req, res) => { autoHideMenuBar, webPreferences, zoomFactor, + suppressNewWindows, } = req.body; if (state.windows[id]) { @@ -317,6 +318,12 @@ router.post('/open', (req, res) => { windowState?.manage(window); } + if (suppressNewWindows) { + window.webContents.setWindowOpenHandler(() => { + return { action: "deny" }; + }); + } + window.on('blur', () => { notifyLaravel('events', { event: 'Native\\Laravel\\Events\\Windows\\WindowBlurred',