Skip to content

Commit

Permalink
initial commit to try to move to the setWindowOpenHandler (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsmaelMartinez authored Mar 24, 2023
1 parent dcb287a commit f460efe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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' };
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit f460efe

Please sign in to comment.