summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-03-02 04:51:45 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2020-03-02 04:51:45 +0200
commit967e99b7f69d24fc76999675cef44b919602dd31 (patch)
tree4128ebda33c7ff04a597f03a2ea46c183ae22f18 /ext/bg/js
parente6e5f23cf8481db31b94c18244f404dd3374ad90 (diff)
ensure Backend prepare in other places
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/backend.js22
-rw-r--r--ext/bg/js/search-frontend.js2
-rw-r--r--ext/bg/js/search.js5
3 files changed, 19 insertions, 10 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index e849bc69..81578462 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -48,7 +48,7 @@ class Backend {
this.messageToken = yomichan.generateId(16);
this._messageHandlers = new Map([
- ['isBackendReady', this._onApiIsBackendReady.bind(this)],
+ ['yomichanOnline', this._onApiYomichanOnline.bind(this)],
['optionsSchemaGet', this._onApiOptionsSchemaGet.bind(this)],
['optionsGet', this._onApiOptionsGet.bind(this)],
['optionsGetFull', this._onApiOptionsGetFull.bind(this)],
@@ -114,19 +114,24 @@ class Backend {
}
this.clipboardMonitor.onClipboardText = this._onClipboardText.bind(this);
- }
- onOptionsUpdated(source) {
- this.applyOptions();
+ this._sendMessageAllTabs('backendPrepared');
+ }
+ _sendMessageAllTabs(action, params={}) {
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.tabs.query({}, (tabs) => {
for (const tab of tabs) {
- chrome.tabs.sendMessage(tab.id, {action: 'optionsUpdated', params: {source}}, callback);
+ chrome.tabs.sendMessage(tab.id, {action, params}, callback);
}
});
}
+ onOptionsUpdated(source) {
+ this.applyOptions();
+ this._sendMessageAllTabs('optionsUpdated', {source});
+ }
+
onMessage({action, params}, sender, callback) {
const handler = this._messageHandlers.get(action);
if (typeof handler !== 'function') { return false; }
@@ -268,8 +273,11 @@ class Backend {
// Message handlers
- async _onApiIsBackendReady() {
- return true;
+ async _onApiYomichanOnline(_params, sender) {
+ const tabId = sender.tab.id;
+ return new Promise((resolve) => {
+ chrome.tabs.sendMessage(tabId, {action: 'backendPrepared'}, resolve);
+ });
}
async _onApiOptionsSchemaGet() {
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index 509c4009..453a0b79 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -19,6 +19,8 @@
/*global apiOptionsGet*/
async function searchFrontendSetup() {
+ await yomichan.prepare();
+
const optionsContext = {
depth: 0,
url: window.location.href
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 0a7a5fe1..f3cba7ae 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -68,9 +68,8 @@ class DisplaySearch extends Display {
async prepare() {
try {
- const superPromise = super.prepare();
- const queryParserPromise = this.queryParser.prepare();
- await Promise.all([superPromise, queryParserPromise]);
+ await super.prepare();
+ await this.queryParser.prepare();
const {queryParams: {query='', mode=''}} = parseUrl(window.location.href);