aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/api.js2
-rw-r--r--ext/bg/js/backend.js41
2 files changed, 27 insertions, 16 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 0b80f099..45dc36e7 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -18,7 +18,7 @@
function apiOptionsGetSync(optionsContext) {
- return utilBackend().options;
+ return utilBackend().getOptions(optionsContext);
}
async function apiOptionsGet(optionsContext) {
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 6afa9617..59de5a50 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -22,6 +22,9 @@ class Backend {
this.translator = new Translator();
this.anki = new AnkiNull();
this.options = null;
+ this.optionsContext = {
+ depth: 0
+ };
this.apiForwarder = new BackendApiForwarder();
}
@@ -35,26 +38,15 @@ class Backend {
}
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
- if (this.options.general.showGuide) {
+ const options = this.getOptions(this.optionsContext);
+ if (options.general.showGuide) {
chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')});
}
}
onOptionsUpdated(options) {
- options = utilIsolate(options);
- this.options = options;
-
- if (!options.general.enable) {
- this.setExtensionBadgeBackgroundColor('#555555');
- this.setExtensionBadgeText('off');
- } else if (!dictConfigured(options)) {
- this.setExtensionBadgeBackgroundColor('#f0ad4e');
- this.setExtensionBadgeText('!');
- } else {
- this.setExtensionBadgeText('');
- }
-
- this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull();
+ this.options = utilIsolate(options);
+ this.applyOptions();
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.tabs.query({}, tabs => {
@@ -136,6 +128,25 @@ class Backend {
return true;
}
+ applyOptions() {
+ const options = this.getOptions(this.optionsContext);
+ if (!options.general.enable) {
+ this.setExtensionBadgeBackgroundColor('#555555');
+ this.setExtensionBadgeText('off');
+ } else if (!dictConfigured(options)) {
+ this.setExtensionBadgeBackgroundColor('#f0ad4e');
+ this.setExtensionBadgeText('!');
+ } else {
+ this.setExtensionBadgeText('');
+ }
+
+ this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull();
+ }
+
+ getOptions(optionsContext) {
+ return this.options;
+ }
+
setExtensionBadgeBackgroundColor(color) {
if (typeof chrome.browserAction.setBadgeBackgroundColor === 'function') {
chrome.browserAction.setBadgeBackgroundColor({color});