From e5af56c82af20f0bd46a2af852f3e0a3a95c1f49 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Tue, 30 Oct 2018 16:35:01 -0700 Subject: [PATCH] app webview: catch new-window message from webview (from openning url in new window) and open in the player window instead cmdline check: check that command line is exactly 2 arguments to avoid opening treating Electron dev mode cmdline as a warc --- app/main.dev.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/main.dev.js b/app/main.dev.js index 7c570e4..dcd0ddb 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -216,7 +216,7 @@ const createWindow = function () { if (openNextFile) { openWarc(openNextFile); - } else if (process.argv.length > 1 && !process.argv[1].startsWith('-psn')) { + } else if (process.argv.length == 2 && !process.argv[1].startsWith('-psn')) { openWarc(process.argv[1]); } @@ -275,6 +275,17 @@ app.on('window-all-closed', () => { app.quit(); }); +// Ensure new-window urls are just opened directly in the webview +app.on('web-contents-created', (e, contents) => { + if (contents.getType() == 'webview') { + // Listen for any new window events on the webview + contents.on('new-window', (e, url) => { + e.preventDefault(); + contents.loadURL(url); + }) + } +}) + app.on('will-finish-launching', function() { app.on('open-file', function(event, filePath) {