From f460efe39217c2ac6ef26c4754d64e39277f58b2 Mon Sep 17 00:00:00 2001 From: IsmaelMartinez Date: Fri, 24 Mar 2023 14:45:22 +0000 Subject: [PATCH] initial commit to try to move to the setWindowOpenHandler (#713) --- app/mainAppWindow/index.js | 25 +++++++++++++------------ package.json | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/mainAppWindow/index.js b/app/mainAppWindow/index.js index ff7c2b0b..37b9529b 100644 --- a/app/mainAppWindow/index.js +++ b/app/mainAppWindow/index.js @@ -37,8 +37,8 @@ exports.onAppReady = async function onAppReady(mainConfig) { window.webContents.send('page-title', title); }); - window.webContents.on('new-window', onNewWindow); - + window.webContents.setWindowOpenHandler(onNewWindow); + window.webContents.session.webRequest.onBeforeRequest({ urls: ['https://*/*'] }, onBeforeRequestHandler); login.handleLoginDialogTry(window); @@ -184,27 +184,28 @@ function onBeforeRequestHandler(details, callback) { } } -function onNewWindow(event, url, frame, disposition, options) { - if (url.startsWith('https://teams.microsoft.com/l/meetup-join')) { - event.preventDefault(); - } else if (url === 'about:blank' || url === 'about:blank#blocked') { - event.preventDefault(); +function onNewWindow(details) { + if (details.url.startsWith('https://teams.microsoft.com/l/meetup-join')) { + logger.debug('DEBUG - captured meetup-join url'); + return { action: 'deny' }; + } else if (details.url === 'about:blank' || details.url === 'about:blank#blocked') { // Increment the counter aboutBlankRequestCount += 1; // Create a new hidden window to load the request in the background logger.debug('DEBUG - captured about:blank'); const win = new BrowserWindow({ - webContents: options.webContents, // use existing webContents if provided + webContents: details.options.webContents, // use existing webContents if provided show: false }); // Close the new window once it is done loading. win.once('ready-to-show', () => win.close()); - event.newGuest = win; - } else if (disposition !== 'background-tab') { - event.preventDefault(); - shell.openExternal(url); + return { action: 'deny' }; + } else if (details.disposition !== 'background-tab') { + logger.debug('DEBUG - captured non background-tab. Opening externally'); + shell.openExternal(details.url); + return { action: 'deny' }; } } diff --git a/package.json b/package.json index 1610383c..0c3c1e1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "teams-for-linux", - "version": "1.0.55", + "version": "1.0.56", "main": "app/index.js", "description": "Unofficial client for Microsoft Teams for Linux", "homepage": "https://github.com/IsmaelMartinez/teams-for-linux",