From f7c3b0010c9c65b418b46bc87bc5e1f321cd94e0 Mon Sep 17 00:00:00 2001
From: toasted-nutbread <toasted-nutbread@users.noreply.github.com>
Date: Sat, 16 Jan 2021 11:33:34 -0500
Subject: Update extension shortcuts (#1246)

* Update commands

* Add command to open the popup window
---
 ext/bg/js/backend.js      | 21 +++++++++++++--------
 ext/bg/js/context-main.js |  8 ++++----
 ext/manifest.json         | 17 +++++++++++++----
 3 files changed, 30 insertions(+), 16 deletions(-)

(limited to 'ext')

diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index d5e5b086..d83942c0 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -131,10 +131,11 @@ class Backend {
         ]);
 
         this._commandHandlers = new Map([
-            ['search',  this._onCommandSearch.bind(this)],
-            ['help',    this._onCommandHelp.bind(this)],
-            ['options', this._onCommandOptions.bind(this)],
-            ['toggle',  this._onCommandToggle.bind(this)]
+            ['toggleTextScanning', this._onCommandToggleTextScanning.bind(this)],
+            ['openHelpPage',       this._onCommandOpenHelpPage.bind(this)],
+            ['openSettingsPage',   this._onCommandOpenSettingsPage.bind(this)],
+            ['openSearchPage',     this._onCommandOpenSearchPage.bind(this)],
+            ['openPopupWindow',    this._onCommandOpenPopupWindow.bind(this)]
         ]);
     }
 
@@ -727,7 +728,7 @@ class Backend {
 
     // Command handlers
 
-    async _onCommandSearch(params) {
+    async _onCommandOpenSearchPage(params) {
         const {mode='existingOrNewTab', query} = params || {};
 
         const baseUrl = chrome.runtime.getURL('/bg/search.html');
@@ -773,22 +774,26 @@ class Backend {
         }
     }
 
-    async _onCommandHelp() {
+    async _onCommandOpenHelpPage() {
         await this._openInfoPage();
     }
 
-    async _onCommandOptions(params) {
+    async _onCommandOpenSettingsPage(params) {
         const {mode='existingOrNewTab'} = params || {};
         await this._openSettingsPage(mode);
     }
 
-    async _onCommandToggle() {
+    async _onCommandToggleTextScanning() {
         const source = 'popup';
         const options = this.getOptions({current: true});
         options.general.enable = !options.general.enable;
         await this._saveOptions(source);
     }
 
+    async _onCommandOpenPopupWindow() {
+        await this._onApiGetOrCreateSearchPopup({focus: true});
+    }
+
     // Utilities
 
     _getOrCreateSearchPopup() {
diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js
index 4db0f096..1d15a81b 100644
--- a/ext/bg/js/context-main.js
+++ b/ext/bg/js/context-main.js
@@ -29,14 +29,14 @@ class DisplayController {
 
         this._showExtensionInfo(manifest);
         this._setupEnvironment();
-        this._setupButtonEvents('.action-open-search', 'search', chrome.runtime.getURL('/bg/search.html'));
-        this._setupButtonEvents('.action-open-help', 'help', chrome.runtime.getURL('/bg/info.html'));
+        this._setupButtonEvents('.action-open-search', 'openSearchPage', chrome.runtime.getURL('/bg/search.html'));
+        this._setupButtonEvents('.action-open-help', 'openHelpPage', chrome.runtime.getURL('/bg/info.html'));
 
         const optionsFull = await api.optionsGetFull();
         this._optionsFull = optionsFull;
 
         const optionsPageUrl = optionsFull.global.useSettingsV2 ? '/bg/settings2.html' : manifest.options_ui.page;
-        this._setupButtonEvents('.action-open-options', 'options', chrome.runtime.getURL(optionsPageUrl));
+        this._setupButtonEvents('.action-open-options', 'openSettingsPage', chrome.runtime.getURL(optionsPageUrl));
 
         const {profiles, profileCurrent} = optionsFull;
         const primaryProfile = (profileCurrent >= 0 && profileCurrent < profiles.length) ? profiles[profileCurrent] : null;
@@ -92,7 +92,7 @@ class DisplayController {
 
     _setupOptions({options}) {
         const extensionEnabled = options.general.enable;
-        const onToggleChanged = () => api.commandExec('toggle');
+        const onToggleChanged = () => api.commandExec('toggleTextScanning');
         for (const toggle of document.querySelectorAll('#enable-search,#enable-search2')) {
             toggle.checked = extensionEnabled;
             toggle.addEventListener('change', onToggleChanged, false);
diff --git a/ext/manifest.json b/ext/manifest.json
index a234d75c..97f77dde 100644
--- a/ext/manifest.json
+++ b/ext/manifest.json
@@ -85,17 +85,26 @@
         "clipboardRead"
     ],
     "commands": {
-        "toggle": {
+        "toggleTextScanning": {
             "suggested_key": {
                 "default": "Alt+Delete"
             },
-            "description": "Toggle text scanning"
+            "description": "Toggle text scanning on/off"
         },
-        "search": {
+        "openHelpPage": {
+            "description": "Open the help page"
+        },
+        "openSettingsPage": {
+            "description": "Open the settings page"
+        },
+        "openSearchPage": {
             "suggested_key": {
                 "default": "Alt+Insert"
             },
-            "description": "Open search window"
+            "description": "Open the search page"
+        },
+        "openPopupWindow": {
+            "description": "Open the popup window"
         }
     },
     "web_accessible_resources": [
-- 
cgit v1.2.3