Skip to content

Commit 67ba81e

Browse files
authored
Merge pull request element-hq#8124 from vector-im/t3chguy/electron-mailto
Correct the copying of e-mail addresses in the electron app
2 parents 05f9cf4 + 8c895cd commit 67ba81e

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

‎electron_app/src/webcontents-handler.js‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const {clipboard, nativeImage, Menu, MenuItem, shell} = require('electron');
22
const url = require('url');
33

4+
const MAILTO_PREFIX = "mailto:";
5+
46
const PERMITTED_URL_SCHEMES = [
57
'http:',
68
'https:',
7-
'mailto:',
9+
MAILTO_PREFIX,
810
];
911

1012
function safeOpenURL(target) {
@@ -47,7 +49,7 @@ function onLinkContextMenu(ev, params) {
4749

4850
if (params.mediaType && params.mediaType === 'image' && !url.startsWith('file://')) {
4951
popupMenu.append(new MenuItem({
50-
label: 'Copy Image',
52+
label: 'Copy image',
5153
click() {
5254
if (url.startsWith('data:')) {
5355
clipboard.writeImage(nativeImage.createFromDataURL(url));
@@ -58,14 +60,24 @@ function onLinkContextMenu(ev, params) {
5860
}));
5961
}
6062

61-
// No point offerring to copy a blob: URL either
63+
// No point offering to copy a blob: URL either
6264
if (!url.startsWith('blob:')) {
63-
popupMenu.append(new MenuItem({
64-
label: 'Copy Link Address',
65-
click() {
66-
clipboard.writeText(url);
67-
},
68-
}));
65+
// Special-case e-mail URLs to strip the `mailto:` like modern browsers do
66+
if (url.startsWith(MAILTO_PREFIX)) {
67+
popupMenu.append(new MenuItem({
68+
label: 'Copy email address',
69+
click() {
70+
clipboard.writeText(url.substr(MAILTO_PREFIX.length));
71+
},
72+
}));
73+
} else {
74+
popupMenu.append(new MenuItem({
75+
label: 'Copy link address',
76+
click() {
77+
clipboard.writeText(url);
78+
},
79+
}));
80+
}
6981
}
7082
// popup() requires an options object even for no options
7183
popupMenu.popup({});

0 commit comments

Comments
 (0)