diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b2f8032f8..9df256e7ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. - ## [1.40.3] - 2023-09-08 diff --git a/src/main/deltachat/webxdc.ts b/src/main/deltachat/webxdc.ts index 4f4b437525..be641834d9 100644 --- a/src/main/deltachat/webxdc.ts +++ b/src/main/deltachat/webxdc.ts @@ -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' @@ -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', diff --git a/src/main/index.ts b/src/main/index.ts index bb106cb7f8..5e115b5408 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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://')) { @@ -255,7 +257,7 @@ 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() @@ -263,7 +265,7 @@ app.on('web-contents-created', (_ev, contents) => { }) } else { contents.on('will-navigate', (e, navigationUrl) => { - log.warn('blocked naviagation attempt to', navigationUrl) + log.warn('blocked navigation attempt to', navigationUrl) e.preventDefault() }) } diff --git a/src/main/windows/html_email.ts b/src/main/windows/html_email.ts index 4e011caa78..70f88f8a75 100644 --- a/src/main/windows/html_email.ts +++ b/src/main/windows/html_email.ts @@ -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') @@ -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) @@ -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) @@ -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 }) @@ -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) + } + }) + } } } ) diff --git a/src/renderer/runtime.ts b/src/renderer/runtime.ts index 25398cb76d..f2b2f22923 100644 --- a/src/renderer/runtime.ts +++ b/src/renderer/runtime.ts @@ -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', (