diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-02-14 18:18:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-14 18:18:02 -0500 |
commit | 48b59375eb50a3c11ab1cbee659164e6991827ac (patch) | |
tree | 160bfe321492839cf3211b27285490e43a7f130d /ext/js/background | |
parent | 9279ced68660610764931da681f22c8b71bf1b6e (diff) |
Cleanup yomichan api (#1394)
* Move invokeMessageHandler to core.js
* Move getMessageResponseResult to backghend.js
* Replace getTemporaryListenerResult
Diffstat (limited to 'ext/js/background')
-rw-r--r-- | ext/js/background/backend.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 698724fc..d88c5853 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -307,7 +307,7 @@ class Backend { } } - return yomichan.invokeMessageHandler(messageHandler, params, callback, sender); + return invokeMessageHandler(messageHandler, params, callback, sender); } _onConnect(port) { @@ -1563,7 +1563,7 @@ class Backend { return new Promise((resolve, reject) => { const callback = (response) => { try { - resolve(yomichan.getMessageResponseResult(response)); + resolve(this._getMessageResponseResult(response)); } catch (error) { reject(error); } @@ -1573,6 +1573,21 @@ class Backend { }); } + _getMessageResponseResult(response) { + let error = chrome.runtime.lastError; + if (error) { + throw new Error(error.message); + } + if (!isObject(response)) { + throw new Error('Tab did not respond'); + } + error = response.error; + if (error) { + throw deserializeError(error); + } + return response.result; + } + async _checkTabUrl(tabId, urlPredicate) { let tab; try { |