Skip to content

Commit

Permalink
feat: Open _blank target links in defaut browser (#2315)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
taratatach authored Aug 3, 2023
2 parents 110a5a6 + 14528d5 commit 6fc623f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gui/js/onboarding.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ 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.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()
Expand All @@ -115,6 +136,10 @@ module.exports = class OnboardingWM extends WindowManager {
}

closeOAuthView() {
if (this.devtools) {
this.win.webContents.openDevTools()
}

if (this.oauthView) {
this.win.removeBrowserView(this.oauthView)
}
Expand Down

0 comments on commit 6fc623f

Please sign in to comment.