Skip to content

Commit

Permalink
fix target=_blank links in html emails don't work (#3409)
Browse files Browse the repository at this point in the history
fixes #3408
  • Loading branch information
Simon-Laux authored Sep 20, 2023
1 parent 1f7dff5 commit 5d03361
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- fix clipboard not working in webxdc apps
- fix `target=_blank` links in html emails don't work #3408

<a id="1_40_4"></a>

Expand Down
47 changes: 28 additions & 19 deletions src/main/windows/html_email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,35 +386,44 @@ function makeBrowserView(
background-color: white;
}`)

const openLink = (url: string) => {
if (url.startsWith('mailto:')) {
open_url(url)
mainWindow.window?.show()
} else {
if (url.startsWith('http:') || url.startsWith('https:')) {
shell.openExternal(url)
} else {
dialog
.showMessageBox(window, {
buttons: [tx('no'), tx('menu_copy_link_to_clipboard')],
message: tx('desktop_offer_copy_non_web_link_to_clipboard', url),
})
.then(({ response }) => {
if (response == 1) {
clipboard.writeText(url)
}
})
}
}
}

sandboxedView.webContents.on(
'will-navigate',
(e: electron.Event, url: string) => {
// Prevent drag-and-drop from navigating the Electron window, which can happen
// before our drag-and-drop handlers have been initialized.
// Also handle clicking links inside of the message.
e.preventDefault()
if (url.startsWith('mailto:')) {
open_url(url)
mainWindow.window?.show()
} else {
if (url.startsWith('http:') || url.startsWith('https:')) {
shell.openExternal(url)
} else {
dialog
.showMessageBox(window, {
buttons: [tx('no'), tx('menu_copy_link_to_clipboard')],
message: tx('desktop_offer_copy_non_web_link_to_clipboard', url),
})
.then(({ response }) => {
if (response == 1) {
clipboard.writeText(url)
}
})
}
}
openLink(url)
}
)

sandboxedView.webContents.setWindowOpenHandler(details => {
openLink(details.url)
return { action: 'deny' }
})

return sandboxedView
}

Expand Down

0 comments on commit 5d03361

Please sign in to comment.