aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-03-04 05:30:48 +0200
committerGitHub <noreply@github.com>2020-03-04 05:30:48 +0200
commit6e47b4e241594d68384f62b1faa34c86f85addbf (patch)
treed70452c259d1aeff36c7a9485cca137b64c58405 /ext/mixed
parent46fee07d36b3966af9bacca8c6253b044bde07ee (diff)
parentde8d9e6bf12f693d6579a2fb965fd7597a04288c (diff)
Merge pull request #386 from siikamiika/simplify-backend-prepare
Simplify backend prepare
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/core.js13
-rw-r--r--ext/mixed/js/display.js1
2 files changed, 14 insertions, 0 deletions
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 83813796..0e22b9ac 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -269,7 +269,11 @@ const yomichan = (() => {
constructor() {
super();
+ this._isBackendPreparedResolve = null;
+ this._isBackendPreparedPromise = new Promise((resolve) => (this._isBackendPreparedResolve = resolve));
+
this._messageHandlers = new Map([
+ ['backendPrepared', this._onBackendPrepared.bind(this)],
['getUrl', this._onMessageGetUrl.bind(this)],
['optionsUpdated', this._onMessageOptionsUpdated.bind(this)],
['zoomChanged', this._onMessageZoomChanged.bind(this)]
@@ -280,6 +284,11 @@ const yomichan = (() => {
// Public
+ prepare() {
+ chrome.runtime.sendMessage({action: 'yomichanCoreReady'});
+ return this._isBackendPreparedPromise;
+ }
+
generateId(length) {
const array = new Uint8Array(length);
window.crypto.getRandomValues(array);
@@ -305,6 +314,10 @@ const yomichan = (() => {
return false;
}
+ _onBackendPrepared() {
+ this._isBackendPreparedResolve();
+ }
+
_onMessageGetUrl() {
return {url: window.location.href};
}
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index e3e5e7df..6a762a65 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -153,6 +153,7 @@ class Display {
}
async prepare(options=null) {
+ await yomichan.prepare();
const displayGeneratorPromise = this.displayGenerator.prepare();
const updateOptionsPromise = this.updateOptions(options);
await Promise.all([displayGeneratorPromise, updateOptionsPromise]);