summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-09-08 19:34:39 -0700
committerGitHub <noreply@github.com>2019-09-08 19:34:39 -0700
commitcc53510883b5c5f75069655df6a6733ff1bd002a (patch)
treeeb600ad20c6df3977db962b0a1b94bc566b8ae6f /ext/bg/js/backend.js
parentc53263158b22f4be8e54696c4675f360f1813de8 (diff)
parenteb98dfb1a86d42a0ecfe54d8eb978c47aa1c0f8b (diff)
Merge pull request #204 from toasted-nutbread/settings-improvements
Settings improvements
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js19
1 files changed, 6 insertions, 13 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 39fd4288..b3e737da 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -28,7 +28,7 @@ class Backend {
async prepare() {
await this.translator.prepare();
- await apiOptionsSet(await optionsLoad());
+ this.onOptionsUpdated(await optionsLoad());
if (chrome.commands !== null && typeof chrome.commands === 'object') {
chrome.commands.onCommand.addListener(this.onCommand.bind(this));
@@ -41,7 +41,8 @@ class Backend {
}
onOptionsUpdated(options) {
- this.options = utilIsolate(options);
+ options = utilIsolate(options);
+ this.options = options;
if (!options.general.enable) {
this.setExtensionBadgeBackgroundColor('#555555');
@@ -53,16 +54,12 @@ class Backend {
this.setExtensionBadgeText('');
}
- if (options.anki.enable) {
- this.anki = new AnkiConnect(options.anki.server);
- } else {
- this.anki = new AnkiNull();
- }
+ this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull();
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.tabs.query({}, tabs => {
for (const tab of tabs) {
- chrome.tabs.sendMessage(tab.id, {action: 'optionsSet', params: options}, callback);
+ chrome.tabs.sendMessage(tab.id, {action: 'optionsSet', params: {options}}, callback);
}
});
}
@@ -85,10 +82,6 @@ class Backend {
forward(apiOptionsGet(), callback);
},
- optionsSet: ({options, callback}) => {
- forward(apiOptionsSet(options), callback);
- },
-
kanjiFind: ({text, callback}) => {
forward(apiKanjiFind(text), callback);
},
@@ -148,7 +141,7 @@ class Backend {
chrome.browserAction.setBadgeBackgroundColor({color});
}
}
-
+
setExtensionBadgeText(text) {
if (typeof chrome.browserAction.setBadgeText === 'function') {
chrome.browserAction.setBadgeText({text});