From c21d6de52d450b6debd0ac45c4ecccf828cc7cb1 Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Thu, 3 Aug 2023 09:20:21 +0200 Subject: [PATCH 1/2] dev: DevTools follow BrowserView changes When we run Desktop in debug mode with DevTools open, we'd like to be able to debug any page of the onboarding process, even the OAuth flow which is a remote website being rendered in a BrowserView. Therefore, we make sure to attach the OAuth BrowserView's DevTools content to our DevTools window when open and to re-attach the main window's DevTools content when closing the OAuth view. --- gui/js/onboarding.window.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gui/js/onboarding.window.js b/gui/js/onboarding.window.js index 3c80552ea..95369e8a0 100644 --- a/gui/js/onboarding.window.js +++ b/gui/js/onboarding.window.js @@ -103,6 +103,14 @@ module.exports = class OnboardingWM extends WindowManager { this.oauthView.setBounds({ ...bounds, x: 0, y: 0 }) this.centerOnScreen(LOGIN_SCREEN_WIDTH, LOGIN_SCREEN_HEIGHT) + if (this.devtools) { + // Switch devtools to current view + this.oauthView.webContents.setDevToolsWebContents( + this.devtools.webContents + ) + this.oauthView.webContents.openDevTools({ mode: 'detach' }) + } + this.oauthView.webContents.on('will-navigate', (event, url) => { if (url.endsWith('.pdf')) { event.preventDefault() @@ -115,6 +123,10 @@ module.exports = class OnboardingWM extends WindowManager { } closeOAuthView() { + if (this.devtools) { + this.win.webContents.openDevTools() + } + if (this.oauthView) { this.win.removeBrowserView(this.oauthView) } From 14528d54c03b296781d979b5a282defd5f127129 Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Thu, 3 Aug 2023 09:28:10 +0200 Subject: [PATCH 2/2] feat: Open _blank target links in defaut browser By default when links have a `_blank` target, Desktop will open the targeted page in a new window. However, we'd like these to be opened in the user's default browser instead as a mechanism to control where links rendered by `cozy-stack` should be opened. --- gui/js/onboarding.window.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gui/js/onboarding.window.js b/gui/js/onboarding.window.js index 95369e8a0..1dfba6055 100644 --- a/gui/js/onboarding.window.js +++ b/gui/js/onboarding.window.js @@ -111,6 +111,19 @@ module.exports = class OnboardingWM extends WindowManager { this.oauthView.webContents.openDevTools({ mode: 'detach' }) } + this.oauthView.webContents.setWindowOpenHandler( + ({ url, disposition }) => { + switch (disposition) { + case 'foreground-tab': + case 'background-tab': + case 'new-window': + shell.openExternal(url) + return { action: 'deny' } + default: + return { action: 'allow' } + } + } + ) this.oauthView.webContents.on('will-navigate', (event, url) => { if (url.endsWith('.pdf')) { event.preventDefault()