diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-09-09 17:46:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 17:46:34 -0400 |
commit | 5d2261acb972374c45fca022f121609405873e90 (patch) | |
tree | cc1feef36ea93ae12784503fe6b3205eb0ed81ce /ext/bg/js/settings/anki-controller.js | |
parent | 8408bee90a0a78a77e7c5834e633a0387f9f434c (diff) |
Update the AnkiController class to use an instance of AnkiConnect directly (#795)
* Update AnkiController to use AnkiConnect instance directly
* Remove unused
Diffstat (limited to 'ext/bg/js/settings/anki-controller.js')
-rw-r--r-- | ext/bg/js/settings/anki-controller.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/bg/js/settings/anki-controller.js b/ext/bg/js/settings/anki-controller.js index 0965e633..c1ba843e 100644 --- a/ext/bg/js/settings/anki-controller.js +++ b/ext/bg/js/settings/anki-controller.js @@ -16,11 +16,12 @@ */ /* global - * api + * AnkiConnect */ class AnkiController { constructor(settingsController) { + this._ankiConnect = new AnkiConnect(); this._settingsController = settingsController; } @@ -100,9 +101,11 @@ class AnkiController { // Private async _onOptionsChanged({options}) { - if (!options.anki.enable) { - return; - } + const {server, enable: enabled} = options.anki; + this._ankiConnect.server = server; + this._ankiConnect.enabled = enabled; + + if (!enabled) { return; } await this._deckAndModelPopulate(options); await Promise.all([ @@ -191,7 +194,10 @@ class AnkiController { const kanjiModel = {value: options.anki.kanji.model, selector: '#anki-kanji-model'}; try { this._spinnerShow(true); - const [deckNames, modelNames] = await Promise.all([api.getAnkiDeckNames(), api.getAnkiModelNames()]); + const [deckNames, modelNames] = await Promise.all([ + this._ankiConnect.getDeckNames(), + this._ankiConnect.getModelNames() + ]); deckNames.sort(); modelNames.sort(); termsDeck.values = deckNames; @@ -262,7 +268,7 @@ class AnkiController { let fieldNames; try { const modelName = node.value; - fieldNames = await api.getAnkiModelFieldNames(modelName); + fieldNames = await this._ankiConnect.getModelFieldNames(modelName); this._setError(null); } catch (error) { this._setError(error); |