diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/anki.js | 9 | ||||
-rw-r--r-- | ext/bg/js/backend.js | 5 | ||||
-rw-r--r-- | ext/mixed/js/api.js | 4 |
3 files changed, 18 insertions, 0 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index 84d81d49..8395518f 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -40,6 +40,15 @@ class AnkiConnect { this._enabled = value; } + async isConnected() { + try { + await this._invoke('version'); + return true; + } catch (e) { + return false; + } + } + async addNote(note) { if (!this._enabled) { return null; } await this._checkVersion(); diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index fe9c9c76..3f00994a 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -83,6 +83,7 @@ class Backend { ['kanjiFind', {async: true, contentScript: true, handler: this._onApiKanjiFind.bind(this)}], ['termsFind', {async: true, contentScript: true, handler: this._onApiTermsFind.bind(this)}], ['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.bind(this)}], + ['isAnkiConnected', {async: true, contentScript: true, handler: this._onApiIsAnkiConnected.bind(this)}], ['addAnkiNote', {async: true, contentScript: true, handler: this._onApiAddAnkiNote.bind(this)}], ['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.bind(this)}], ['injectAnkiNoteMedia', {async: true, contentScript: true, handler: this._onApiInjectAnkiNoteMedia.bind(this)}], @@ -420,6 +421,10 @@ class Backend { return results; } + async _onApiIsAnkiConnected() { + return await this._anki.isConnected(); + } + async _onApiAddAnkiNote({note}) { return await this._anki.addNote(note); } diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index 43db1562..947f1cd8 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -69,6 +69,10 @@ const api = (() => { return this._invoke('kanjiFind', {text, optionsContext}); } + isAnkiConnected() { + return this._invoke('isAnkiConnected'); + } + addAnkiNote(note) { return this._invoke('addAnkiNote', {note}); } |