Skip to content

Commit

Permalink
Offer to copy non-HTTP links to the clipboard instead of trying to op…
Browse files Browse the repository at this point in the history
…en them in webxdc source code link and inside of html emails. (#3395)

* Offer to copy non-HTTP links to the clipboard instead of trying to open them in webxdc source code link and inside of html emails.

* fix unreachable duplicated check for mailto scheme

* fix duplicated calling of 'open-url'

* - fix html mail getting restrictions of webxdc window
- fix: when clicking on mailto link in html email show main window even when it was hidden.
  • Loading branch information
Simon-Laux authored Sep 14, 2023
1 parent 0fe279c commit bde5536
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
### Added

### Changed
- Offer to copy non-HTTP links to the clipboard instead of trying to open them in webxdc source code link and inside of html emails.
- update electron from `v22.3.23` to version `v22.3.24`

### Fixed
- fix duplicated calling of 'open-url'
- fix html mail getting restrictions of webxdc window
- fix: when clicking on mailto link in html email show main window even when it was hidden.
- Display the toast after successful key import.


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

## [1.40.3] - 2023-09-08
Expand Down
31 changes: 28 additions & 3 deletions src/main/deltachat/webxdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
nativeImage,
shell,
MenuItemConstructorOptions,
clipboard,
dialog,
} from 'electron'
import { join } from 'path'
import { readdir, stat, rmdir, writeFile, readFile } from 'fs/promises'
Expand Down Expand Up @@ -321,9 +323,32 @@ export default class DCWebxdc extends SplitOut {
label: tx('source_code'),
enabled: !!webxdcInfo.sourceCodeUrl,
icon: app_icon?.resize({ width: 24 }) || undefined,
click: () =>
webxdcInfo.sourceCodeUrl &&
shell.openExternal(webxdcInfo.sourceCodeUrl),
click: () => {
if (
webxdcInfo.sourceCodeUrl?.startsWith('https:') ||
webxdcInfo.sourceCodeUrl?.startsWith('http:')
) {
shell.openExternal(webxdcInfo.sourceCodeUrl)
} else if (webxdcInfo.sourceCodeUrl) {
const url = webxdcInfo.sourceCodeUrl
dialog
.showMessageBox(webxdc_windows, {
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)
}
})
}
},
},
{
type: 'separator',
Expand Down
8 changes: 5 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ app.on('before-quit', e => quit(e))
app.on('window-all-closed', (e: Electron.Event) => quit(e))

app.on('web-contents-created', (_ev, contents) => {
const is_webxdc = contents.session.storagePath?.indexOf('webxdc_') !== -1
const is_webxdc =
contents.session.storagePath &&
contents.session.storagePath.indexOf('webxdc_') !== -1
if (is_webxdc) {
contents.on('will-navigate', (e, navigationUrl) => {
if (navigationUrl.startsWith('webxdc://')) {
Expand All @@ -255,15 +257,15 @@ app.on('web-contents-created', (_ev, contents) => {
// handle mailto in dc
e.preventDefault()
open_url(navigationUrl)
mainWindow.window?.focus()
mainWindow.window?.show()
} else {
// prevent navigation to unknown scheme
e.preventDefault()
}
})
} else {
contents.on('will-navigate', (e, navigationUrl) => {
log.warn('blocked naviagation attempt to', navigationUrl)
log.warn('blocked navigation attempt to', navigationUrl)
e.preventDefault()
})
}
Expand Down
31 changes: 27 additions & 4 deletions src/main/windows/html_email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { open_url } from '../open_url'
import { loadTheme } from '../themes'
import { getDCJsonrpcClient } from '../ipc'
import { getLogger } from '../../shared/logger'
import { clipboard } from 'electron/common'
import * as mainWindow from './main'

const log = getLogger('html_email')

Expand Down Expand Up @@ -131,7 +133,8 @@ export function openHtmlEmailWindow(
let sandboxedView: BrowserView = makeBrowserView(
account_id,
loadRemoteContentAtStart,
htmlEmail
htmlEmail,
window
)
window.setBrowserView(sandboxedView)
let context_menu_handle = createContextMenu(window, sandboxedView.webContents)
Expand Down Expand Up @@ -261,7 +264,12 @@ export function openHtmlEmailWindow(
window.removeBrowserView(sandboxedView)
context_menu_handle()
sandboxedView.webContents.close()
sandboxedView = makeBrowserView(account_id, allow_network, htmlEmail)
sandboxedView = makeBrowserView(
account_id,
allow_network,
htmlEmail,
window
)
window.setBrowserView(sandboxedView)
context_menu_handle = createContextMenu(window, sandboxedView.webContents)
if (bounds) sandboxedView.setBounds(bounds)
Expand Down Expand Up @@ -298,7 +306,8 @@ script-src 'none';
function makeBrowserView(
account_id: number,
allow_remote_content: boolean,
html_content: string
html_content: string,
window: BrowserWindow
) {
const ses = session.fromPartition(`${Date.now()}`, { cache: false })

Expand Down Expand Up @@ -386,8 +395,22 @@ function makeBrowserView(
e.preventDefault()
if (url.startsWith('mailto:')) {
open_url(url)
mainWindow.window?.show()
} else {
shell.openExternal(url)
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)
}
})
}
}
}
)
Expand Down
1 change: 0 additions & 1 deletion src/renderer/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ class Electron implements Runtime {
)
ipcBackend.on('showSettingsDialog', () => this.onShowDialog?.('settings'))
ipcBackend.on('open-url', (_ev, url) => this.onOpenQrUrl?.(url))
ipcBackend.on('open-url', (_ev, url) => this.onOpenQrUrl?.(url))
ipcBackend.on(
'webxdc.sendToChat',
(
Expand Down

0 comments on commit bde5536

Please sign in to comment.