summaryrefslogtreecommitdiff
path: root/ext/js/comm/anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-05-29 21:24:41 -0400
committerGitHub <noreply@github.com>2022-05-29 21:24:41 -0400
commit331a2e62941e04a4d50a21faefed663a92ddc00a (patch)
tree1212a1e7cd57ea2331fab2101afdc325cb3a4766 /ext/js/comm/anki.js
parentf3024c50186344aa6a6b09500ea02540463ce5c9 (diff)
Add support for guiEditNote to view notes (#2143)
* Add AnkiConnect.guiEditNote * Update _onApiNoteView to first try guiEditNote * Add setting * Update noteView API * Use setting * Return which mode was used * Update DisplayGenerator * Handle errors in DisplayAnki * Update docs * Add isErrorUnsupportedAction function * Add an allowFallback option to noteView * Disambiguate * Simplify now that preferredMode isn't used * Update settings info * Implement test buttons * Update styles * Update status visibility * Wrap layout * Update description * Update date
Diffstat (limited to 'ext/js/comm/anki.js')
-rw-r--r--ext/js/comm/anki.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/js/comm/anki.js b/ext/js/comm/anki.js
index 7ffb747b..f5dc62f2 100644
--- a/ext/js/comm/anki.js
+++ b/ext/js/comm/anki.js
@@ -106,6 +106,15 @@ class AnkiConnect {
}
/**
+ * Opens the note editor GUI.
+ * @param {number} noteId The ID of the note.
+ * @returns {Promise<null>} Nothing is returned.
+ */
+ async guiEditNote(noteId) {
+ return await this._invoke('guiEditNote', {note: noteId});
+ }
+
+ /**
* Stores a file with the specified base64-encoded content inside Anki's media folder.
* @param {string} fileName The name of the file.
* @param {string} content The base64-encoded content of the file.
@@ -187,6 +196,21 @@ class AnkiConnect {
return actions.includes(action);
}
+ /**
+ * Checks if a specific error object corresponds to an unsupported action.
+ * @param {Error} error An error object generated by an API call.
+ * @returns {boolean} Whether or not the error indicates the action is not supported.
+ */
+ isErrorUnsupportedAction(error) {
+ if (error instanceof Error) {
+ const {data} = error;
+ if (isObject(data) && data.apiError === 'unsupported action') {
+ return true;
+ }
+ }
+ return false;
+ }
+
// Private
async _checkVersion() {