aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-07 14:21:26 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-10 20:09:33 -0400
commit1b2a1e50ebcd62cf54b397516e991333afa5158c (patch)
tree2dd31c4e907eb18125b4178c0e8b74c8be00de2f /ext/bg/js/backend.js
parentbc8793eb56b2ce985f2e5dc0a9fd270f98fbf17a (diff)
Add getOptions function to backend
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js41
1 files changed, 26 insertions, 15 deletions
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});