Fix tabs opening twice (fix #1209) (#1221)

* Only add a new window handler to the main window

* Update app/src/components/mainWindow.ts

Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>

Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>
This commit is contained in:
Adam Weeden 2021-06-07 16:49:06 -04:00 committed by GitHub
parent 460d70f915
commit 363fa966ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 21 deletions

View File

@ -11,7 +11,7 @@ import {
isOSX,
nativeTabsSupported,
} from '../helpers/helpers';
import { setupNativefierWindow } from '../helpers/windowEvents';
import { onNewWindow, setupNativefierWindow } from '../helpers/windowEvents';
import {
clearCache,
getDefaultWindowOptions,
@ -88,6 +88,32 @@ export async function createMainWindow(
createContextMenu(options, mainWindow);
setupNativefierWindow(options, mainWindow);
// .on('new-window', ...) is deprected in favor of setWindowOpenHandler(...)
// We can't quite cut over to that yet for a few reasons:
// 1. Our version of Electron does not yet support a parameter to
// setWindowOpenHandler that contains `disposition', which we need.
// See https://github.com/electron/electron/issues/28380
// 2. setWindowOpenHandler doesn't support newGuest as well
// Though at this point, 'new-window' bugs seem to be coming up and downstream
// users are being pointed to use setWindowOpenHandler.
// E.g., https://github.com/electron/electron/issues/28374
// Note it is important to add this handler only to the *main* window,
// else we run into weird behavior like opening tabs twice
mainWindow.webContents.on(
'new-window',
(event, url, frameName, disposition) => {
onNewWindow(
options,
setupNativefierWindow,
event,
url,
frameName,
disposition,
).catch((err) => log.error('onNewWindow ERROR', err));
},
);
if (options.counter) {
setupCounter(options, mainWindow, setDockBadge);
} else {

View File

@ -151,26 +151,6 @@ export function setupNativefierWindow(options, window: BrowserWindow): void {
injectCSS(window);
// .on('new-window', ...) is deprected in favor of setWindowOpenHandler(...)
// We can't quite cut over to that yet for a few reasons:
// 1. Our version of Electron does not yet support a parameter to
// setWindowOpenHandler that contains `disposition', which we need.
// See https://github.com/electron/electron/issues/28380
// 2. setWindowOpenHandler doesn't support newGuest as well
// Though at this point, 'new-window' bugs seem to be coming up and downstream
// users are being pointed to use setWindowOpenHandler.
// E.g., https://github.com/electron/electron/issues/28374
window.webContents.on('new-window', (event, url, frameName, disposition) => {
onNewWindow(
options,
setupNativefierWindow,
event,
url,
frameName,
disposition,
).catch((err) => log.error('onNewWindow ERROR', err));
});
window.webContents.on('will-navigate', (event: IpcMainEvent, url: string) => {
onWillNavigate(options, event, url).catch((err) => {
log.error(' window.webContents.on.will-navigate ERROR', err);