aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
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() {