Merge pull request #1708 from warrickct/link-visit-confirmation

Link visit confirmation
This commit is contained in:
Audric Ackermann 2021-06-22 11:26:55 +10:00 committed by GitHub
commit bc3819aab7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View file

@ -419,5 +419,8 @@
"device": "Device",
"destination": "Destination",
"learnMore": "Learn more",
"playAtCustomSpeed": "Play at $multipler$x speed"
"playAtCustomSpeed": "Play at $multipler$x speed",
"linkVisitWarningTitle": "Open this link in your browser?",
"linkVisitWarningMessage": "Are you sure you want to open $url$ in your browser?",
"open": "Open"
}

View file

@ -4,7 +4,8 @@ import LinkifyIt from 'linkify-it';
import { RenderTextCallbackType } from '../../types/Util';
import { isLinkSneaky } from '../../../js/modules/link_previews';
import { SessionHtmlRenderer } from '../session/SessionHTMLRenderer';
import { updateConfirmModal } from '../../state/ducks/modalDialog';
import { shell } from 'electron';
const linkify = LinkifyIt();
@ -70,6 +71,25 @@ export class Linkify extends React.Component<Props> {
// disable click on <a> elements so clicking a message containing a link doesn't
// select the message.The link will still be opened in the browser.
public handleClick = (e: any) => {
e.preventDefault();
e.stopPropagation();
const url = e.target.href;
const openLink = () => {
void shell.openExternal(url);
};
window.inboxStore?.dispatch(
updateConfirmModal({
title: window.i18n('linkVisitWarningTitle'),
message: window.i18n('linkVisitWarningMessage', url),
okText: window.i18n('open'),
onClickOk: openLink,
onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null));
},
})
);
};
}