summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-07 19:59:10 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-07 19:59:10 -0400
commitc88ec43ad1523fefaa47b6e46dd0fa95f342559c (patch)
tree179df0c60894421eae764614f4a314f12da646d4 /ext/bg/js/backend.js
parenta2b66dc6cc3bd0d037c050eb49e270189a6617fb (diff)
Fix yomichanCoreReady waiting for a response
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js17
1 files changed, 8 insertions, 9 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index c471c594..35e75bbe 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -77,7 +77,7 @@ class Backend {
this.messageToken = yomichan.generateId(16);
this._messageHandlers = new Map([
- ['yomichanCoreReady', {handler: this._onApiYomichanCoreReady.bind(this), async: true}],
+ ['yomichanCoreReady', {handler: this._onApiYomichanCoreReady.bind(this), async: false}],
['optionsSchemaGet', {handler: this._onApiOptionsSchemaGet.bind(this), async: false}],
['optionsGet', {handler: this._onApiOptionsGet.bind(this), async: false}],
['optionsGetFull', {handler: this._onApiOptionsGetFull.bind(this), async: false}],
@@ -320,16 +320,15 @@ class Backend {
_onApiYomichanCoreReady(_params, sender) {
// tab ID isn't set in background (e.g. browser_action)
+ const callback = () => this.checkLastError(chrome.runtime.lastError);
+ const data = {action: 'backendPrepared'};
if (typeof sender.tab === 'undefined') {
- const callback = () => this.checkLastError(chrome.runtime.lastError);
- chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
- return Promise.resolve();
+ chrome.runtime.sendMessage(data, callback);
+ return false;
+ } else {
+ chrome.tabs.sendMessage(sender.tab.id, data, callback);
+ return true;
}
-
- const tabId = sender.tab.id;
- return new Promise((resolve) => {
- chrome.tabs.sendMessage(tabId, {action: 'backendPrepared'}, resolve);
- });
}
_onApiOptionsSchemaGet() {