Merge pull request #6765 from vector-im/dbkr/electron_hide_nonsensical_menu_options

Hide URL options for e2e blob: URL images
This commit is contained in:
David Baker 2018-05-18 12:18:09 +01:00 committed by GitHub
commit 2e7da36af0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,12 +35,15 @@ function onLinkContextMenu(ev, params) {
const url = params.linkURL || params.srcURL; const url = params.linkURL || params.srcURL;
const popupMenu = new Menu(); const popupMenu = new Menu();
// No point trying to open blob: URLs in an external browser: it ain't gonna work.
if (!url.startsWith('blob:')) {
popupMenu.append(new MenuItem({ popupMenu.append(new MenuItem({
label: url, label: url,
click() { click() {
safeOpenURL(url); safeOpenURL(url);
}, },
})); }));
}
if (params.mediaType && params.mediaType === 'image' && !url.startsWith('file://')) { if (params.mediaType && params.mediaType === 'image' && !url.startsWith('file://')) {
popupMenu.append(new MenuItem({ popupMenu.append(new MenuItem({
@ -55,12 +58,15 @@ function onLinkContextMenu(ev, params) {
})); }));
} }
// No point offerring to copy a blob: URL either
if (!url.startsWith('blob:')) {
popupMenu.append(new MenuItem({ popupMenu.append(new MenuItem({
label: 'Copy Link Address', label: 'Copy Link Address',
click() { click() {
clipboard.writeText(url); clipboard.writeText(url);
}, },
})); }));
}
// popup() requires an options object even for no options // popup() requires an options object even for no options
popupMenu.popup({}); popupMenu.popup({});
ev.preventDefault(); ev.preventDefault();