aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.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/backend.js
parente6e5f23cf8481db31b94c18244f404dd3374ad90 (diff)
ensure Backend prepare in other places
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js22
1 files changed, 15 insertions, 7 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() {