diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-16 11:33:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 11:33:34 -0500 |
commit | f7c3b0010c9c65b418b46bc87bc5e1f321cd94e0 (patch) | |
tree | efb7aaed4fae1dc1f532ce255be5cef8103ece6d | |
parent | 8766744aa4a94193dd03bba39086e4522914e8ef (diff) |
Update extension shortcuts (#1246)
* Update commands
* Add command to open the popup window
-rw-r--r-- | dev/data/manifest-variants.json | 17 | ||||
-rw-r--r-- | ext/bg/js/backend.js | 21 | ||||
-rw-r--r-- | ext/bg/js/context-main.js | 8 | ||||
-rw-r--r-- | ext/manifest.json | 17 |
4 files changed, 43 insertions, 20 deletions
diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json index 8286a4b8..d94ed9ab 100644 --- a/dev/data/manifest-variants.json +++ b/dev/data/manifest-variants.json @@ -86,17 +86,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": [ 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": [ |