summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/backend.js15
-rw-r--r--ext/bg/js/settings/anki-controller.js18
-rw-r--r--ext/mixed/js/api.js12
3 files changed, 12 insertions, 33 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index df979c6f..5fdca569 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -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();
}
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);
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js
index 701caba8..2192fa98 100644
--- a/ext/mixed/js/api.js
+++ b/ext/mixed/js/api.js
@@ -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');
}