From 48b59375eb50a3c11ab1cbee659164e6991827ac Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 14 Feb 2021 18:18:02 -0500 Subject: Cleanup yomichan api (#1394) * Move invokeMessageHandler to core.js * Move getMessageResponseResult to backghend.js * Replace getTemporaryListenerResult --- ext/js/background/backend.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'ext/js/background') 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 { -- cgit v1.2.3