mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-25 09:03:42 +00:00
* This will make sure that the current server webview will not reload due to URL change. * Add an option to allow users to download the file attachments. Improves: #469.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const { shell } = require('electron').remote;
|
|
const LinkUtil = require('../utils/link-util');
|
|
const DomainUtil = require('../utils/domain-util');
|
|
const hiddenWebView = require('../components/hidden-webview');
|
|
|
|
function handleExternalLink(event) {
|
|
const { url } = event;
|
|
const domainPrefix = DomainUtil.getDomain(this.props.index).url;
|
|
|
|
// Whitelist URLs which are allowed to be opened in the app
|
|
const {
|
|
isInternalUrl: isWhiteListURL,
|
|
isUploadsUrl: isUploadsURL
|
|
} = LinkUtil.isInternal(domainPrefix, url);
|
|
|
|
if (isWhiteListURL) {
|
|
event.preventDefault();
|
|
|
|
// only open the pdf, mp3, mp4 etc.. in hidden webview since opening the
|
|
// image in webview will do nothing and will not save it
|
|
// whereas the pdf will be saved to user desktop once openened in
|
|
// in the hidden webview and will not trigger webview reload
|
|
if (!LinkUtil.isImage(url) && isUploadsURL) {
|
|
hiddenWebView.loadURL(url);
|
|
return;
|
|
}
|
|
|
|
// open internal urls inside the current webview.
|
|
this.$el.loadURL(url);
|
|
} else {
|
|
event.preventDefault();
|
|
shell.openExternal(url);
|
|
}
|
|
}
|
|
|
|
module.exports = handleExternalLink;
|