summaryrefslogtreecommitdiff
path: root/ext/mixed/js/yomichan.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-18 14:18:10 -0400
committerGitHub <noreply@github.com>2020-07-18 14:18:10 -0400
commitc6c0126394f4bf5862061aaa5be7f941ff957a07 (patch)
tree7fab40bbb647d2cfc8819e05ad9175f70c8db036 /ext/mixed/js/yomichan.js
parentffc0b6588e9f95d873fe87db6ba647a27c0a8b3d (diff)
Content script ready checks (#670)
* Move ready checkout of Display * Add function to wait until if a tab's content script is ready
Diffstat (limited to 'ext/mixed/js/yomichan.js')
-rw-r--r--ext/mixed/js/yomichan.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js
index 33870658..3ae905c3 100644
--- a/ext/mixed/js/yomichan.js
+++ b/ext/mixed/js/yomichan.js
@@ -48,12 +48,14 @@ const yomichan = (() => {
}
this._isExtensionUnloaded = false;
+ this._isReady = false;
const {promise, resolve} = deferPromise();
this._isBackendPreparedPromise = promise;
this._isBackendPreparedPromiseResolve = resolve;
this._messageHandlers = new Map([
+ ['isReady', {async: false, handler: this._onMessageIsReady.bind(this)}],
['backendPrepared', {async: false, handler: this._onMessageBackendPrepared.bind(this)}],
['getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}],
['optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}],
@@ -72,6 +74,7 @@ const yomichan = (() => {
}
ready() {
+ this._isReady = true;
this.sendMessage({action: 'yomichanCoreReady'});
return this._isBackendPreparedPromise;
}
@@ -268,6 +271,10 @@ const yomichan = (() => {
return this.invokeMessageHandler(messageHandler, params, callback, sender);
}
+ _onMessageIsReady() {
+ return this._isReady;
+ }
+
_onMessageBackendPrepared() {
if (this._isBackendPreparedPromiseResolve === null) { return; }
this._isBackendPreparedPromiseResolve();