Update the AnkiController class to use an instance of AnkiConnect directly (#795)

* Update AnkiController to use AnkiConnect instance directly

* Remove unused
This commit is contained in:
toasted-nutbread 2020-09-09 17:46:34 -04:00 committed by GitHub
parent 8408bee90a
commit 5d2261acb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 33 deletions

View File

@ -113,9 +113,6 @@ class Backend {
['getQueryParserTemplatesHtml', {async: true, contentScript: true, handler: this._onApiGetQueryParserTemplatesHtml.bind(this)}],
['getZoom', {async: true, contentScript: true, handler: this._onApiGetZoom.bind(this)}],
['getDefaultAnkiFieldTemplates', {async: false, contentScript: true, handler: this._onApiGetDefaultAnkiFieldTemplates.bind(this)}],
['getAnkiDeckNames', {async: true, contentScript: false, handler: this._onApiGetAnkiDeckNames.bind(this)}],
['getAnkiModelNames', {async: true, contentScript: false, handler: this._onApiGetAnkiModelNames.bind(this)}],
['getAnkiModelFieldNames', {async: true, contentScript: false, handler: this._onApiGetAnkiModelFieldNames.bind(this)}],
['getDictionaryInfo', {async: true, contentScript: false, handler: this._onApiGetDictionaryInfo.bind(this)}],
['getDictionaryCounts', {async: true, contentScript: false, handler: this._onApiGetDictionaryCounts.bind(this)}],
['purgeDatabase', {async: true, contentScript: false, handler: this._onApiPurgeDatabase.bind(this)}],
@ -726,18 +723,6 @@ class Backend {
return this._defaultAnkiFieldTemplates;
}
async _onApiGetAnkiDeckNames() {
return await this._anki.getDeckNames();
}
async _onApiGetAnkiModelNames() {
return await this._anki.getModelNames();
}
async _onApiGetAnkiModelFieldNames({modelName}) {
return await this._anki.getModelFieldNames(modelName);
}
async _onApiGetDictionaryInfo() {
return await this._dictionaryDatabase.getDictionaryInfo();
}

View File

@ -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);

View File

@ -153,18 +153,6 @@ const api = (() => {
return this._invoke('getDefaultAnkiFieldTemplates');
}
getAnkiDeckNames() {
return this._invoke('getAnkiDeckNames');
}
getAnkiModelNames() {
return this._invoke('getAnkiModelNames');
}
getAnkiModelFieldNames(modelName) {
return this._invoke('getAnkiModelFieldNames', {modelName});
}
getDictionaryInfo() {
return this._invoke('getDictionaryInfo');
}