From fa47e905c5de77b17ba5ddecd22601bcd2ca0b4e Mon Sep 17 00:00:00 2001 From: Abdo Date: Fri, 28 Jun 2024 15:38:18 +0300 Subject: [PATCH] Restore $deckOptions (#3265) * Restore $deckOptions * Avoid error in logs when using ./yarn dev or mobile clients (dae) --- qt/aqt/deckoptions.py | 6 +++++- ts/lib/tslib/bridgecommand.ts | 4 ++++ ts/routes/deck-options/[deckId]/+page.svelte | 14 +++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/qt/aqt/deckoptions.py b/qt/aqt/deckoptions.py index f53c047ed..28600545c 100644 --- a/qt/aqt/deckoptions.py +++ b/qt/aqt/deckoptions.py @@ -43,6 +43,7 @@ class DeckOptionsDialog(QDialog): addCloseShortcut(self) self.web = AnkiWebView(kind=AnkiWebViewKind.DECK_OPTIONS) + self.web.set_bridge_command(self._on_bridge_cmd, self) self.web.load_sveltekit_page(f"deck-options/{self._deck['id']}") layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) @@ -53,7 +54,10 @@ class DeckOptionsDialog(QDialog): self.setWindowTitle( without_unicode_isolation(tr.actions_options_for(val=self._deck["name"])) ) - gui_hooks.deck_options_did_load(self) + + def _on_bridge_cmd(self, cmd: str) -> None: + if cmd == "deckOptionsReady": + gui_hooks.deck_options_did_load(self) def reject(self) -> None: self.mw.col.set_wants_abort() diff --git a/ts/lib/tslib/bridgecommand.ts b/ts/lib/tslib/bridgecommand.ts index 84bcb4918..141c71d71 100644 --- a/ts/lib/tslib/bridgecommand.ts +++ b/ts/lib/tslib/bridgecommand.ts @@ -14,6 +14,10 @@ export function bridgeLink(command: string, label: string): string { return `${label}`; } +export function bridgeCommandsAvailable(): boolean { + return !!window.bridgeCommand; +} + export function bridgeCommand(command: string, callback?: (value: T) => void): void { window.bridgeCommand(command, callback); } diff --git a/ts/routes/deck-options/[deckId]/+page.svelte b/ts/routes/deck-options/[deckId]/+page.svelte index de55607c6..11af70f71 100644 --- a/ts/routes/deck-options/[deckId]/+page.svelte +++ b/ts/routes/deck-options/[deckId]/+page.svelte @@ -3,10 +3,22 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> - +