aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/yomichan.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-18 17:11:38 -0400
committerGitHub <noreply@github.com>2020-07-18 17:11:38 -0400
commitd7f78c23b50218eaa52ab4570a1e2297c52c287e (patch)
tree64a217ccc1f96efeec3c81e1d16215963536c733 /ext/mixed/js/yomichan.js
parente696dc84a857e60adcfa7feec44398765c430cac (diff)
Script ready state change (#672)
* Update how backend/frontend ready states are awaited and signaled * Log errors on the search page * Update action name
Diffstat (limited to 'ext/mixed/js/yomichan.js')
-rw-r--r--ext/mixed/js/yomichan.js30
1 files changed, 17 insertions, 13 deletions
diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js
index 3ae905c3..6eba68b2 100644
--- a/ext/mixed/js/yomichan.js
+++ b/ext/mixed/js/yomichan.js
@@ -51,15 +51,15 @@ const yomichan = (() => {
this._isReady = false;
const {promise, resolve} = deferPromise();
- this._isBackendPreparedPromise = promise;
- this._isBackendPreparedPromiseResolve = resolve;
+ this._isBackendReadyPromise = promise;
+ this._isBackendReadyPromiseResolve = 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)}],
- ['zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}]
+ ['isReady', {async: false, handler: this._onMessageIsReady.bind(this)}],
+ ['backendReady', {async: false, handler: this._onMessageBackendReady.bind(this)}],
+ ['getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}],
+ ['optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}],
+ ['zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}]
]);
}
@@ -73,10 +73,14 @@ const yomichan = (() => {
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
}
+ backendReady() {
+ this.sendMessage({action: 'requestBackendReadySignal'});
+ return this._isBackendReadyPromise;
+ }
+
ready() {
this._isReady = true;
- this.sendMessage({action: 'yomichanCoreReady'});
- return this._isBackendPreparedPromise;
+ this.sendMessage({action: 'yomichanReady'});
}
generateId(length) {
@@ -275,10 +279,10 @@ const yomichan = (() => {
return this._isReady;
}
- _onMessageBackendPrepared() {
- if (this._isBackendPreparedPromiseResolve === null) { return; }
- this._isBackendPreparedPromiseResolve();
- this._isBackendPreparedPromiseResolve = null;
+ _onMessageBackendReady() {
+ if (this._isBackendReadyPromiseResolve === null) { return; }
+ this._isBackendReadyPromiseResolve();
+ this._isBackendReadyPromiseResolve = null;
}
_onMessageGetUrl() {