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)}], ['getQueryParserTemplatesHtml', {async: true, contentScript: true, handler: this._onApiGetQueryParserTemplatesHtml.bind(this)}],
['getZoom', {async: true, contentScript: true, handler: this._onApiGetZoom.bind(this)}], ['getZoom', {async: true, contentScript: true, handler: this._onApiGetZoom.bind(this)}],
['getDefaultAnkiFieldTemplates', {async: false, contentScript: true, handler: this._onApiGetDefaultAnkiFieldTemplates.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)}], ['getDictionaryInfo', {async: true, contentScript: false, handler: this._onApiGetDictionaryInfo.bind(this)}],
['getDictionaryCounts', {async: true, contentScript: false, handler: this._onApiGetDictionaryCounts.bind(this)}], ['getDictionaryCounts', {async: true, contentScript: false, handler: this._onApiGetDictionaryCounts.bind(this)}],
['purgeDatabase', {async: true, contentScript: false, handler: this._onApiPurgeDatabase.bind(this)}], ['purgeDatabase', {async: true, contentScript: false, handler: this._onApiPurgeDatabase.bind(this)}],
@ -726,18 +723,6 @@ class Backend {
return this._defaultAnkiFieldTemplates; 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() { async _onApiGetDictionaryInfo() {
return await this._dictionaryDatabase.getDictionaryInfo(); return await this._dictionaryDatabase.getDictionaryInfo();
} }

View File

@ -16,11 +16,12 @@
*/ */
/* global /* global
* api * AnkiConnect
*/ */
class AnkiController { class AnkiController {
constructor(settingsController) { constructor(settingsController) {
this._ankiConnect = new AnkiConnect();
this._settingsController = settingsController; this._settingsController = settingsController;
} }
@ -100,9 +101,11 @@ class AnkiController {
// Private // Private
async _onOptionsChanged({options}) { async _onOptionsChanged({options}) {
if (!options.anki.enable) { const {server, enable: enabled} = options.anki;
return; this._ankiConnect.server = server;
} this._ankiConnect.enabled = enabled;
if (!enabled) { return; }
await this._deckAndModelPopulate(options); await this._deckAndModelPopulate(options);
await Promise.all([ await Promise.all([
@ -191,7 +194,10 @@ class AnkiController {
const kanjiModel = {value: options.anki.kanji.model, selector: '#anki-kanji-model'}; const kanjiModel = {value: options.anki.kanji.model, selector: '#anki-kanji-model'};
try { try {
this._spinnerShow(true); 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(); deckNames.sort();
modelNames.sort(); modelNames.sort();
termsDeck.values = deckNames; termsDeck.values = deckNames;
@ -262,7 +268,7 @@ class AnkiController {
let fieldNames; let fieldNames;
try { try {
const modelName = node.value; const modelName = node.value;
fieldNames = await api.getAnkiModelFieldNames(modelName); fieldNames = await this._ankiConnect.getModelFieldNames(modelName);
this._setError(null); this._setError(null);
} catch (error) { } catch (error) {
this._setError(error); this._setError(error);

View File

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