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/background/backend.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'ext/js/background') diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index cdbfde1e..07d6fd98 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -512,8 +512,22 @@ class Backend { ); } - async _onApiNoteView({noteId}) { - return await this._anki.guiBrowseNote(noteId); + async _onApiNoteView({noteId, mode, allowFallback}) { + if (mode === 'edit') { + try { + await this._anki.guiEditNote(noteId); + return 'edit'; + } catch (e) { + if (!this._anki.isErrorUnsupportedAction(e)) { + throw e; + } else if (!allowFallback) { + throw new Error('Mode not supported'); + } + } + } + // Fallback + await this._anki.guiBrowseNote(noteId); + return 'browse'; } async _onApiSuspendAnkiCardsForNote({noteId}) { -- cgit v1.2.3