From 587d6150857b1ae4fb44bd8bdf85af5cc78729c2 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Sat, 26 May 2018 19:50:36 -0700 Subject: [PATCH] Fix #616 - Only override the default window opening behavior when necessary (#620) As part of #591, all window creation was routed through a createNewWindow function. That change introduced the regression reported in #616 in which popup windows could not communicate with their parent windows. This change reverts that behavior for windows opened via JavaScript (that aren't being opened as tabs and aren't being opened in external browsers), thereby fixing the reported regression. --- app/src/components/mainWindow/mainWindow.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/components/mainWindow/mainWindow.js b/app/src/components/mainWindow/mainWindow.js index d22a325..d1a43ec 100644 --- a/app/src/components/mainWindow/mainWindow.js +++ b/app/src/components/mainWindow/mainWindow.js @@ -210,22 +210,30 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) { }; const onNewWindow = (event, urlToGo, _, disposition) => { - event.preventDefault(); + const preventDefault = (newGuest) => { + event.preventDefault(); + if (newGuest) { + // eslint-disable-next-line no-param-reassign + event.newGuest = newGuest; + } + }; if (nativeTabsSupported()) { if (disposition === 'background-tab') { - createNewTab(urlToGo, false); + const newTab = createNewTab(urlToGo, false); + preventDefault(newTab); return; } else if (disposition === 'foreground-tab') { - createNewTab(urlToGo, true); + const newTab = createNewTab(urlToGo, true); + preventDefault(newTab); return; } } if (!linkIsInternal(options.targetUrl, urlToGo, options.internalUrls)) { shell.openExternal(urlToGo); + preventDefault(); + // eslint-disable-next-line no-useless-return return; } - // eslint-disable-next-line no-param-reassign - event.newGuest = createNewWindow(urlToGo); }; const sendParamsOnDidFinishLoad = (window) => {