Skip to content

Commit ce8a88e

Browse files
authored
Optionally prevent opening of sub-windows (#249)
1 parent 4670a7f commit ce8a88e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

resources/js/electron-plugin/dist/server/api/window.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function getWindowData(id) {
145145
};
146146
}
147147
router.post('/open', (req, res) => {
148-
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;
148+
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;
149149
if (state.windows[id]) {
150150
state.windows[id].show();
151151
state.windows[id].focus();
@@ -197,6 +197,11 @@ router.post('/open', (req, res) => {
197197
if (req.body.rememberState === true) {
198198
windowState === null || windowState === void 0 ? void 0 : windowState.manage(window);
199199
}
200+
if (suppressNewWindows) {
201+
window.webContents.setWindowOpenHandler(() => {
202+
return { action: "deny" };
203+
});
204+
}
200205
window.on('blur', () => {
201206
notifyLaravel('events', {
202207
event: 'Native\\Laravel\\Events\\Windows\\WindowBlurred',

resources/js/electron-plugin/src/server/api/window.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ router.post('/open', (req, res) => {
234234
autoHideMenuBar,
235235
webPreferences,
236236
zoomFactor,
237+
suppressNewWindows,
237238
} = req.body;
238239

239240
if (state.windows[id]) {
@@ -317,6 +318,12 @@ router.post('/open', (req, res) => {
317318
windowState?.manage(window);
318319
}
319320

321+
if (suppressNewWindows) {
322+
window.webContents.setWindowOpenHandler(() => {
323+
return { action: "deny" };
324+
});
325+
}
326+
320327
window.on('blur', () => {
321328
notifyLaravel('events', {
322329
event: 'Native\\Laravel\\Events\\Windows\\WindowBlurred',

0 commit comments

Comments
 (0)