Skip to content

Commit

Permalink
Only open windows externally if window is focused (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeichestakov authored May 2, 2024
1 parent d70076f commit d03a292
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/createWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
}
}
});

Expand Down

0 comments on commit d03a292

Please sign in to comment.