Correct the copying of e-mail addresses in the electron app
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
99b5695fec
commit
8c895cd435
|
@ -1,10 +1,12 @@
|
||||||
const {clipboard, nativeImage, Menu, MenuItem, shell} = require('electron');
|
const {clipboard, nativeImage, Menu, MenuItem, shell} = require('electron');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
|
const MAILTO_PREFIX = "mailto:";
|
||||||
|
|
||||||
const PERMITTED_URL_SCHEMES = [
|
const PERMITTED_URL_SCHEMES = [
|
||||||
'http:',
|
'http:',
|
||||||
'https:',
|
'https:',
|
||||||
'mailto:',
|
MAILTO_PREFIX,
|
||||||
];
|
];
|
||||||
|
|
||||||
function safeOpenURL(target) {
|
function safeOpenURL(target) {
|
||||||
|
@ -47,7 +49,7 @@ function onLinkContextMenu(ev, params) {
|
||||||
|
|
||||||
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({
|
||||||
label: 'Copy Image',
|
label: 'Copy image',
|
||||||
click() {
|
click() {
|
||||||
if (url.startsWith('data:')) {
|
if (url.startsWith('data:')) {
|
||||||
clipboard.writeImage(nativeImage.createFromDataURL(url));
|
clipboard.writeImage(nativeImage.createFromDataURL(url));
|
||||||
|
@ -58,15 +60,25 @@ function onLinkContextMenu(ev, params) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// No point offerring to copy a blob: URL either
|
// No point offering to copy a blob: URL either
|
||||||
if (!url.startsWith('blob:')) {
|
if (!url.startsWith('blob:')) {
|
||||||
|
// Special-case e-mail URLs to strip the `mailto:` like modern browsers do
|
||||||
|
if (url.startsWith(MAILTO_PREFIX)) {
|
||||||
popupMenu.append(new MenuItem({
|
popupMenu.append(new MenuItem({
|
||||||
label: 'Copy Link Address',
|
label: 'Copy email address',
|
||||||
|
click() {
|
||||||
|
clipboard.writeText(url.substr(MAILTO_PREFIX.length));
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
popupMenu.append(new MenuItem({
|
||||||
|
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();
|
||||||
|
|
Loading…
Reference in New Issue