From af15ae525061a2ccbed6c2ead50f5c8869833e32 Mon Sep 17 00:00:00 2001 From: sergeichestakov Date: Wed, 1 May 2024 12:40:01 -0400 Subject: [PATCH] Only open windows externally if window is focused --- src/createWindow.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/createWindow.ts b/src/createWindow.ts index d1c29b6..633712c 100644 --- a/src/createWindow.ts +++ b/src/createWindow.ts @@ -195,8 +195,11 @@ export function createWindow(props?: WindowProps): BrowserWindow { }; } - log.info('Opening external URL in window open handler: ', details); - shell.openExternal(details.url); + // Only open externally if the window is actually focused to prevent windows from opening in the background. + if (window.isFocused()) { + log.info('Opening external URL in window open handler: ', details); + shell.openExternal(details.url); + } return { action: 'deny', @@ -221,8 +224,15 @@ export function createWindow(props?: WindowProps): BrowserWindow { } event.preventDefault(); - log.info('Opening external URL in will-navigate event handler: ', event); - shell.openExternal(event.url); + + // Only open externally if the window is actually focused to prevent windows from opening in the background. + if (window.isFocused()) { + log.info( + 'Opening external URL in will-navigate event handler: ', + event, + ); + shell.openExternal(event.url); + } } });