aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-05-19 22:14:56 +0530
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-05-19 23:04:23 +0530
commit6125d3c00cb353432fcbd0c4a6272fba2c1ea7b6 (patch)
treee72c4f3f751efe3fca003e387a8131159d77595e
parentDowngraded 'electron-is-dev' since that is causing Ferdi to come up with a bl... (diff)
downloadferdium-app-6125d3c00cb353432fcbd0c4a6272fba2c1ea7b6.tar.gz
ferdium-app-6125d3c00cb353432fcbd0c4a6272fba2c1ea7b6.tar.zst
ferdium-app-6125d3c00cb353432fcbd0c4a6272fba2c1ea7b6.zip
Implemented a new 'copy to clipboard' menuitem in context menu.
-rw-r--r--src/webview/contextMenuBuilder.js48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/webview/contextMenuBuilder.js b/src/webview/contextMenuBuilder.js
index 49c4550a9..a1a733a75 100644
--- a/src/webview/contextMenuBuilder.js
+++ b/src/webview/contextMenuBuilder.js
@@ -39,6 +39,7 @@ const contextMenuStringTable = {
39 addToDictionary: () => 'Add to Dictionary', 39 addToDictionary: () => 'Add to Dictionary',
40 goBack: () => 'Go Back', 40 goBack: () => 'Go Back',
41 goForward: () => 'Go Forward', 41 goForward: () => 'Go Forward',
42 copyPageUrl: () => 'Copy Page URL',
42 goToHomePage: () => 'Go to Home Page', 43 goToHomePage: () => 'Go to Home Page',
43 copyMail: () => 'Copy Email Address', 44 copyMail: () => 'Copy Email Address',
44 inspectElement: () => 'Inspect Element', 45 inspectElement: () => 'Inspect Element',
@@ -139,6 +140,7 @@ module.exports = class ContextMenuBuilder {
139 this.addInspectElement(menu, menuInfo); 140 this.addInspectElement(menu, menuInfo);
140 this.processMenu(menu, menuInfo); 141 this.processMenu(menu, menuInfo);
141 142
143 this.copyPageUrl(menu);
142 this.goToHomePage(menu, menuInfo); 144 this.goToHomePage(menu, menuInfo);
143 this.openInBrowser(menu, menuInfo); 145 this.openInBrowser(menu, menuInfo);
144 146
@@ -158,8 +160,9 @@ module.exports = class ContextMenuBuilder {
158 label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(), 160 label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
159 click: () => { 161 click: () => {
160 // Omit the mailto: portion of the link; we just want the address 162 // Omit the mailto: portion of the link; we just want the address
161 clipboard.writeText(isEmailAddress 163 const url = isEmailAddress ? menuInfo.linkText : menuInfo.linkURL;
162 ? menuInfo.linkText : menuInfo.linkURL); 164 clipboard.writeText(url);
165 this.sendNotificationOnClipboardEvent(`Link URL copied: ${url}`);
163 }, 166 },
164 }); 167 });
165 168
@@ -191,6 +194,7 @@ module.exports = class ContextMenuBuilder {
191 194
192 this.goBack(menu); 195 this.goBack(menu);
193 this.goForward(menu); 196 this.goForward(menu);
197 this.copyPageUrl(menu);
194 this.goToHomePage(menu, menuInfo); 198 this.goToHomePage(menu, menuInfo);
195 this.openInBrowser(menu, menuInfo); 199 this.openInBrowser(menu, menuInfo);
196 200
@@ -212,6 +216,7 @@ module.exports = class ContextMenuBuilder {
212 216
213 this.goBack(menu); 217 this.goBack(menu);
214 this.goForward(menu); 218 this.goForward(menu);
219 this.copyPageUrl(menu);
215 this.goToHomePage(menu, menuInfo); 220 this.goToHomePage(menu, menuInfo);
216 this.openInBrowser(menu, menuInfo); 221 this.openInBrowser(menu, menuInfo);
217 222
@@ -311,15 +316,24 @@ module.exports = class ContextMenuBuilder {
311 addImageItems(menu, menuInfo) { 316 addImageItems(menu, menuInfo) {
312 const copyImage = new MenuItem({ 317 const copyImage = new MenuItem({
313 label: this.stringTable.copyImage(), 318 label: this.stringTable.copyImage(),
314 click: () => this.convertImageToBase64(menuInfo.srcURL, 319 click: () => {
315 dataURL => clipboard.writeImage(nativeImage.createFromDataURL(dataURL))), 320 const result = this.convertImageToBase64(menuInfo.srcURL,
321 dataURL => clipboard.writeImage(nativeImage.createFromDataURL(dataURL)));
322
323 this.sendNotificationOnClipboardEvent(`Image copied from URL: ${menuInfo.srcURL}`);
324 return result;
325 },
316 }); 326 });
317 327
318 menu.append(copyImage); 328 menu.append(copyImage);
319 329
320 const copyImageUrl = new MenuItem({ 330 const copyImageUrl = new MenuItem({
321 label: this.stringTable.copyImageUrl(), 331 label: this.stringTable.copyImageUrl(),
322 click: () => clipboard.writeText(menuInfo.srcURL), 332 click: () => {
333 const result = clipboard.writeText(menuInfo.srcURL);
334 this.sendNotificationOnClipboardEvent(`Image URL copied: ${menuInfo.srcURL}`);
335 return result;
336 },
323 }); 337 });
324 338
325 menu.append(copyImageUrl); 339 menu.append(copyImageUrl);
@@ -471,6 +485,22 @@ module.exports = class ContextMenuBuilder {
471 } 485 }
472 486
473 /** 487 /**
488 * Adds the 'copy page url' menu item.
489 */
490 copyPageUrl(menu) {
491 menu.append(new MenuItem({
492 label: this.stringTable.copyPageUrl(),
493 enabled: true,
494 click: () => {
495 clipboard.writeText(window.location.href);
496 this.sendNotificationOnClipboardEvent(`Page URL copied: ${window.location.href}`);
497 },
498 }));
499
500 return menu;
501 }
502
503 /**
474 * Adds the 'go to home' menu item. 504 * Adds the 'go to home' menu item.
475 */ 505 */
476 goToHomePage(menu, menuInfo) { 506 goToHomePage(menu, menuInfo) {
@@ -502,4 +532,12 @@ module.exports = class ContextMenuBuilder {
502 532
503 return menu; 533 return menu;
504 } 534 }
535
536 sendNotificationOnClipboardEvent(notificationText) {
537 // eslint-disable-next-line no-new
538 new window.Notification('Data copied into Clipboard',
539 {
540 body: notificationText,
541 });
542 }
505}; 543};