From 079765bad8a577d140166098e8dd0b7fe0660e4e Mon Sep 17 00:00:00 2001 From: Vijay Raghavan Aravamudhan Date: Sat, 5 Jun 2021 16:28:52 +0530 Subject: Added ability to turn off notifications for clipboard events generated by context menu actions (#1494) --- src/webview/contextMenu.js | 4 ++-- src/webview/contextMenuBuilder.js | 17 ++++++++++------- src/webview/recipe.js | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/webview') diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index f19d863ee..567a2d470 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js @@ -3,7 +3,7 @@ import ContextMenuBuilder from './contextMenuBuilder'; const webContents = getCurrentWebContents(); -export default async function setupContextMenu(isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage, getSearchEngine) { +export default async function setupContextMenu(isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage, getSearchEngine, getClipboardNotifications) { const contextMenuBuilder = new ContextMenuBuilder( webContents, ); @@ -11,7 +11,7 @@ export default async function setupContextMenu(isSpellcheckEnabled, getDefaultSp webContents.on('context-menu', (e, props) => { // TODO?: e.preventDefault(); contextMenuBuilder.showPopupMenu( - { ...props, searchEngine: getSearchEngine() }, + { ...props, searchEngine: getSearchEngine(), clipboardNotifications: getClipboardNotifications() }, isSpellcheckEnabled(), getDefaultSpellcheckerLanguage(), getSpellcheckerLanguage(), diff --git a/src/webview/contextMenuBuilder.js b/src/webview/contextMenuBuilder.js index 7c178145d..c26f192fe 100644 --- a/src/webview/contextMenuBuilder.js +++ b/src/webview/contextMenuBuilder.js @@ -161,7 +161,7 @@ module.exports = class ContextMenuBuilder { // Omit the mailto: portion of the link; we just want the address const url = isEmailAddress ? menuInfo.linkText : menuInfo.linkURL; clipboard.writeText(url); - this.sendNotificationOnClipboardEvent(`Link URL copied: ${url}`); + this._sendNotificationOnClipboardEvent(menuInfo.clipboardNotifications, () => `Link URL copied: ${url}`); }, }); @@ -321,7 +321,7 @@ module.exports = class ContextMenuBuilder { const result = this.convertImageToBase64(menuInfo.srcURL, dataURL => clipboard.writeImage(nativeImage.createFromDataURL(dataURL))); - this.sendNotificationOnClipboardEvent(`Image copied from URL: ${menuInfo.srcURL}`); + this._sendNotificationOnClipboardEvent(menuInfo.clipboardNotifications, () => `Image copied from URL: ${menuInfo.srcURL}`); return result; }, }); @@ -332,7 +332,7 @@ module.exports = class ContextMenuBuilder { label: this.stringTable.copyImageUrl(), click: () => { const result = clipboard.writeText(menuInfo.srcURL); - this.sendNotificationOnClipboardEvent(`Image URL copied: ${menuInfo.srcURL}`); + this._sendNotificationOnClipboardEvent(menuInfo.clipboardNotifications, () => `Image URL copied: ${menuInfo.srcURL}`); return result; }, }); @@ -357,7 +357,7 @@ module.exports = class ContextMenuBuilder { }, }); }); - this.sendNotificationOnClipboardEvent(`Image downloaded: ${urlWithoutBlob}`); + this._sendNotificationOnClipboardEvent(menuInfo.clipboardNotifications, () => `Image downloaded: ${urlWithoutBlob}`); }, }); @@ -520,7 +520,7 @@ module.exports = class ContextMenuBuilder { enabled: true, click: () => { clipboard.writeText(window.location.href); - this.sendNotificationOnClipboardEvent(`Page URL copied: ${window.location.href}`); + this._sendNotificationOnClipboardEvent(menu.clipboardNotifications, () => `Page URL copied: ${window.location.href}`); }, })); @@ -560,11 +560,14 @@ module.exports = class ContextMenuBuilder { return menu; } - sendNotificationOnClipboardEvent(notificationText) { + _sendNotificationOnClipboardEvent(isDisabled, notificationText) { + if (isDisabled) { + return; + } // eslint-disable-next-line no-new new window.Notification('Data copied into Clipboard', { - body: notificationText, + body: notificationText(), }); } }; diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 5a24effa2..6c382d388 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js @@ -92,6 +92,7 @@ class RecipeController { () => this.settings.app.spellcheckerLanguage, () => this.spellcheckerLanguage, () => this.settings.app.searchEngine, + () => this.settings.app.clipboardNotifications, ); autorun(() => this.update()); -- cgit v1.2.3-54-g00ecf