Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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. #3395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

@r10s r10s Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compared to #3388, in the bubbles, mailto: links are passed to processOpenQrUrl(link) instead of shell.openExternal() - is that difference on purpose?

in general, bubble-view and full-message-view should behave quite similar from the user perspective - a link may fit randomly to a bubble or not, but they should act the same (it is a pity that we cannot use the same dialogs in both szenarios, btw)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a duplicated artefact that comes from copy pasting see 2 lines above. also processOpenQrUrl exist only in the frontend, so the open_url function is for forwarding the request to the frontend.

} 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