Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the copying of e-mail addresses in the electron app #8124

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions electron_app/src/webcontents-handler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const {clipboard, nativeImage, Menu, MenuItem, shell} = require('electron');
const url = require('url');

const MAILTO_PREFIX = "mailto:";

const PERMITTED_URL_SCHEMES = [
'http:',
'https:',
'mailto:',
MAILTO_PREFIX,
];

function safeOpenURL(target) {
Expand Down Expand Up @@ -47,7 +49,7 @@ function onLinkContextMenu(ev, params) {

if (params.mediaType && params.mediaType === 'image' && !url.startsWith('file://')) {
popupMenu.append(new MenuItem({
label: 'Copy Image',
label: 'Copy image',
click() {
if (url.startsWith('data:')) {
clipboard.writeImage(nativeImage.createFromDataURL(url));
Expand All @@ -58,14 +60,24 @@ 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:')) {
popupMenu.append(new MenuItem({
label: 'Copy Link Address',
click() {
clipboard.writeText(url);
},
}));
// Special-case e-mail URLs to strip the `mailto:` like modern browsers do
if (url.startsWith(MAILTO_PREFIX)) {
popupMenu.append(new MenuItem({
label: 'Copy email address',
click() {
clipboard.writeText(url.substr(MAILTO_PREFIX.length));
},
}));
} else {
popupMenu.append(new MenuItem({
label: 'Copy link address',
click() {
clipboard.writeText(url);
},
}));
}
}
// popup() requires an options object even for no options
popupMenu.popup({});
Expand Down
2 changes: 1 addition & 1 deletion src/vector/rageshakesetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
*/

import rageshake from "matrix-react-sdk/lib/rageshake/rageshake";
import SdkConfig from "matrix-react-sdk/src/SdkConfig";
import SdkConfig from "matrix-react-sdk/lib/SdkConfig";

function initRageshake() {
rageshake.init().then(() => {
Expand Down