mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 08:33:36 +00:00
This commit download file attachments using downloadURL method of
webContent, the same way loadURL opens internal links. This
removes the use of hidden webview added in
f70432f4e3.
Improves: #469.
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const { shell } = require('electron').remote;
|
|
const LinkUtil = require('../utils/link-util');
|
|
const DomainUtil = require('../utils/domain-util');
|
|
|
|
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();
|
|
|
|
// download txt, pdf, mp3, mp4 etc.. by using downloadURL in the
|
|
// main process which allows the user to save the files to their desktop
|
|
// and not trigger webview reload while image in webview will
|
|
// do nothing and will not save it
|
|
if (!LinkUtil.isImage(url) && isUploadsURL) {
|
|
this.$el.downloadURL(url);
|
|
return;
|
|
}
|
|
|
|
// open internal urls inside the current webview.
|
|
this.$el.loadURL(url);
|
|
} else {
|
|
event.preventDefault();
|
|
shell.openExternal(url);
|
|
}
|
|
}
|
|
|
|
module.exports = handleExternalLink;
|