From 331a2e62941e04a4d50a21faefed663a92ddc00a Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 29 May 2022 21:24:41 -0400 Subject: 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 --- ext/js/comm/anki.js | 24 ++++++++++++++++++++++++ ext/js/comm/api.js | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'ext/js/comm') 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 @@ -105,6 +105,15 @@ class AnkiConnect { return await this.guiBrowse(`nid:${noteId}`); } + /** + * Opens the note editor GUI. + * @param {number} noteId The ID of the note. + * @returns {Promise} 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. @@ -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() { diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index 75a01dd5..2ffe2d8c 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -60,8 +60,8 @@ class API { return this._invoke('injectAnkiNoteMedia', {timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails, dictionaryMediaDetails}); } - noteView(noteId) { - return this._invoke('noteView', {noteId}); + noteView(noteId, mode, allowFallback) { + return this._invoke('noteView', {noteId, mode, allowFallback}); } suspendAnkiCardsForNote(noteId) { -- cgit v1.2.3