diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-07 15:06:15 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-10 20:09:33 -0400 |
commit | 8175f80183caa0673a946b2405feae0c9535af48 (patch) | |
tree | 9ceb126a6164704aa3bdcfbbdb13d9d89590972b /ext/bg/js/backend.js | |
parent | 1b2a1e50ebcd62cf54b397516e991333afa5158c (diff) |
Remove calls to apiOptionsGetSync
Use apiOptionsGet everywhere to ensure options is initialized.
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r-- | ext/bg/js/backend.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 59de5a50..6dcf8e4d 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -26,6 +26,9 @@ class Backend { depth: 0 }; + this.isPreparedResolve = null; + this.isPreparedPromise = new Promise((resolve) => (this.isPreparedResolve = resolve)); + this.apiForwarder = new BackendApiForwarder(); } @@ -38,10 +41,14 @@ class Backend { } chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); - const options = this.getOptions(this.optionsContext); + const options = this.getOptionsSync(this.optionsContext); if (options.general.showGuide) { chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')}); } + + this.isPreparedResolve(); + this.isPreparedResolve = null; + this.isPreparedPromise = null; } onOptionsUpdated(options) { @@ -129,7 +136,7 @@ class Backend { } applyOptions() { - const options = this.getOptions(this.optionsContext); + const options = this.getOptionsSync(this.optionsContext); if (!options.general.enable) { this.setExtensionBadgeBackgroundColor('#555555'); this.setExtensionBadgeText('off'); @@ -143,7 +150,14 @@ class Backend { this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull(); } - getOptions(optionsContext) { + async getOptions(optionsContext) { + if (this.isPreparedPromise !== null) { + await this.isPreparedPromise; + } + return this.getOptionsSync(optionsContext); + } + + getOptionsSync(optionsContext) { return this.options; } |