Add api.isAnkiConnected (#1011)
This commit is contained in:
parent
0cbc6523e6
commit
4e30409410
@ -40,6 +40,15 @@ class AnkiConnect {
|
|||||||
this._enabled = value;
|
this._enabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async isConnected() {
|
||||||
|
try {
|
||||||
|
await this._invoke('version');
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async addNote(note) {
|
async addNote(note) {
|
||||||
if (!this._enabled) { return null; }
|
if (!this._enabled) { return null; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
|
@ -83,6 +83,7 @@ class Backend {
|
|||||||
['kanjiFind', {async: true, contentScript: true, handler: this._onApiKanjiFind.bind(this)}],
|
['kanjiFind', {async: true, contentScript: true, handler: this._onApiKanjiFind.bind(this)}],
|
||||||
['termsFind', {async: true, contentScript: true, handler: this._onApiTermsFind.bind(this)}],
|
['termsFind', {async: true, contentScript: true, handler: this._onApiTermsFind.bind(this)}],
|
||||||
['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.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)}],
|
['addAnkiNote', {async: true, contentScript: true, handler: this._onApiAddAnkiNote.bind(this)}],
|
||||||
['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.bind(this)}],
|
['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.bind(this)}],
|
||||||
['injectAnkiNoteMedia', {async: true, contentScript: true, handler: this._onApiInjectAnkiNoteMedia.bind(this)}],
|
['injectAnkiNoteMedia', {async: true, contentScript: true, handler: this._onApiInjectAnkiNoteMedia.bind(this)}],
|
||||||
@ -420,6 +421,10 @@ class Backend {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _onApiIsAnkiConnected() {
|
||||||
|
return await this._anki.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
async _onApiAddAnkiNote({note}) {
|
async _onApiAddAnkiNote({note}) {
|
||||||
return await this._anki.addNote(note);
|
return await this._anki.addNote(note);
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,10 @@ const api = (() => {
|
|||||||
return this._invoke('kanjiFind', {text, optionsContext});
|
return this._invoke('kanjiFind', {text, optionsContext});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAnkiConnected() {
|
||||||
|
return this._invoke('isAnkiConnected');
|
||||||
|
}
|
||||||
|
|
||||||
addAnkiNote(note) {
|
addAnkiNote(note) {
|
||||||
return this._invoke('addAnkiNote', {note});
|
return this._invoke('addAnkiNote', {note});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user