aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js')
-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]);