summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-12 12:37:13 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-12 12:37:13 -0400
commitc41c7252aeb5f10fca7403a19740d869743a38a5 (patch)
tree9ec1f0e55906579ee393371a7c26e20be74efab0 /ext/bg/js/anki.js
parentade1b705d2370be9222ba4164f79bbdfae590bc1 (diff)
Add enabled checks
Diffstat (limited to 'ext/bg/js/anki.js')
-rw-r--r--ext/bg/js/anki.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index 021cb4c4..f7a24291 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -25,47 +25,74 @@
class AnkiConnect {
constructor(server) {
+ this._enabled = true;
this._server = server;
this._localVersion = 2;
this._remoteVersion = 0;
}
+ setServer(server) {
+ this._server = server;
+ }
+
+ getServer() {
+ return this._server;
+ }
+
+ setEnabled(enabled) {
+ this._enabled = enabled;
+ }
+
+ isEnabled() {
+ return this._enabled;
+ }
+
async addNote(note) {
+ if (!this._enabled) { return null; }
await this._checkVersion();
return await this._ankiInvoke('addNote', {note});
}
async canAddNotes(notes) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('canAddNotes', {notes});
}
async getDeckNames() {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('deckNames');
}
async getModelNames() {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('modelNames');
}
async getModelFieldNames(modelName) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('modelFieldNames', {modelName});
}
async guiBrowse(query) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('guiBrowse', {query});
}
async storeMediaFile(filename, dataBase64) {
+ if (!this._enabled) {
+ return {result: null, error: 'AnkiConnect not enabled'};
+ }
await this._checkVersion();
return await this._ankiInvoke('storeMediaFile', {filename, data: dataBase64});
}
async findNoteIds(notes) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
const actions = notes.map((note) => ({
action: 'findNotes',