summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/backend.js12
-rw-r--r--ext/bg/js/util.js2
2 files changed, 9 insertions, 5 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 9d1fa6c1..f5bd36f5 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -67,8 +67,6 @@ class Backend {
url: window.location.href
};
- this.isPrepared = false;
-
this.clipboardPasteTarget = document.querySelector('#clipboard-paste-target');
this.popupWindow = null;
@@ -77,6 +75,8 @@ class Backend {
this.messageToken = yomichan.generateId(16);
+ this._isPrepared = false;
+
this._messageHandlers = new Map([
['yomichanCoreReady', {handler: this._onApiYomichanCoreReady.bind(this), async: false}],
['optionsSchemaGet', {handler: this._onApiOptionsSchemaGet.bind(this), async: false}],
@@ -144,8 +144,6 @@ class Backend {
}
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
- this.isPrepared = true;
-
const options = this.getOptions(this.optionsContext);
if (options.general.showGuide) {
chrome.tabs.create({url: chrome.runtime.getURL('/bg/guide.html')});
@@ -156,6 +154,12 @@ class Backend {
this._sendMessageAllTabs('backendPrepared');
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
+
+ this._isPrepared = true;
+ }
+
+ isPrepared() {
+ return this._isPrepared;
}
_sendMessageAllTabs(action, params={}) {
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 5edcc193..d2fb0e49 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -60,7 +60,7 @@ function utilBackgroundFunctionIsolate(func) {
function utilBackend() {
const backend = chrome.extension.getBackgroundPage().yomichanBackend;
- if (!backend.isPrepared) {
+ if (!backend.isPrepared()) {
throw new Error('Backend not ready yet');
}
return backend;