aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/offscreen.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-20 00:18:55 -0500
committerGitHub <noreply@github.com>2023-12-20 05:18:55 +0000
commit3c226215419ca815712e9568f7d871a96f5ff1cf (patch)
tree8bfe561a0d36589860b64c1758c2e29e92e7e3f4 /ext/js/background/offscreen.js
parente0e29dc1aa0965b3e0fb97de64a27c2b695e068b (diff)
Simplify message handlers (#396)
Diffstat (limited to 'ext/js/background/offscreen.js')
-rw-r--r--ext/js/background/offscreen.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/ext/js/background/offscreen.js b/ext/js/background/offscreen.js
index 85b6847b..bcbcda6b 100644
--- a/ext/js/background/offscreen.js
+++ b/ext/js/background/offscreen.js
@@ -52,23 +52,21 @@ export class Offscreen {
/* eslint-disable no-multi-spaces */
/** @type {import('offscreen').MessageHandlerMap} */
- const messageHandlers = new Map([
- ['clipboardGetTextOffscreen', {async: true, handler: this._getTextHandler.bind(this)}],
- ['clipboardGetImageOffscreen', {async: true, handler: this._getImageHandler.bind(this)}],
- ['clipboardSetBrowserOffscreen', {async: false, handler: this._setClipboardBrowser.bind(this)}],
- ['databasePrepareOffscreen', {async: true, handler: this._prepareDatabaseHandler.bind(this)}],
- ['getDictionaryInfoOffscreen', {async: true, handler: this._getDictionaryInfoHandler.bind(this)}],
- ['databasePurgeOffscreen', {async: true, handler: this._purgeDatabaseHandler.bind(this)}],
- ['databaseGetMediaOffscreen', {async: true, handler: this._getMediaHandler.bind(this)}],
- ['translatorPrepareOffscreen', {async: false, handler: this._prepareTranslatorHandler.bind(this)}],
- ['findKanjiOffscreen', {async: true, handler: this._findKanjiHandler.bind(this)}],
- ['findTermsOffscreen', {async: true, handler: this._findTermsHandler.bind(this)}],
- ['getTermFrequenciesOffscreen', {async: true, handler: this._getTermFrequenciesHandler.bind(this)}],
- ['clearDatabaseCachesOffscreen', {async: false, handler: this._clearDatabaseCachesHandler.bind(this)}]
- ]);
+ this._messageHandlers = new Map(/** @type {import('offscreen').MessageHandlerMapInit} */ ([
+ ['clipboardGetTextOffscreen', this._getTextHandler.bind(this)],
+ ['clipboardGetImageOffscreen', this._getImageHandler.bind(this)],
+ ['clipboardSetBrowserOffscreen', this._setClipboardBrowser.bind(this)],
+ ['databasePrepareOffscreen', this._prepareDatabaseHandler.bind(this)],
+ ['getDictionaryInfoOffscreen', this._getDictionaryInfoHandler.bind(this)],
+ ['databasePurgeOffscreen', this._purgeDatabaseHandler.bind(this)],
+ ['databaseGetMediaOffscreen', this._getMediaHandler.bind(this)],
+ ['translatorPrepareOffscreen', this._prepareTranslatorHandler.bind(this)],
+ ['findKanjiOffscreen', this._findKanjiHandler.bind(this)],
+ ['findTermsOffscreen', this._findTermsHandler.bind(this)],
+ ['getTermFrequenciesOffscreen', this._getTermFrequenciesHandler.bind(this)],
+ ['clearDatabaseCachesOffscreen', this._clearDatabaseCachesHandler.bind(this)]
+ ]));
/* eslint-enable no-multi-spaces */
- /** @type {import('offscreen').MessageHandlerMap<string>} */
- this._messageHandlers = messageHandlers;
const onMessage = this._onMessage.bind(this);
chrome.runtime.onMessage.addListener(onMessage);
@@ -172,7 +170,7 @@ export class Offscreen {
/** @type {import('extension').ChromeRuntimeOnMessageCallback} */
_onMessage({action, params}, sender, callback) {
- const messageHandler = this._messageHandlers.get(action);
+ const messageHandler = this._messageHandlers.get(/** @type {import('offscreen').MessageType} */ (action));
if (typeof messageHandler === 'undefined') { return false; }
return invokeMessageHandler(messageHandler, params, callback, sender);
}