Restore $deckOptions (#3265)

* Restore $deckOptions

* Avoid error in logs when using ./yarn dev or mobile clients (dae)
This commit is contained in:
Abdo 2024-06-28 15:38:18 +03:00 committed by GitHub
parent 55d68c01d8
commit fa47e905c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View File

@ -43,6 +43,7 @@ class DeckOptionsDialog(QDialog):
addCloseShortcut(self) addCloseShortcut(self)
self.web = AnkiWebView(kind=AnkiWebViewKind.DECK_OPTIONS) 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']}") self.web.load_sveltekit_page(f"deck-options/{self._deck['id']}")
layout = QVBoxLayout() layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
@ -53,7 +54,10 @@ class DeckOptionsDialog(QDialog):
self.setWindowTitle( self.setWindowTitle(
without_unicode_isolation(tr.actions_options_for(val=self._deck["name"])) 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: def reject(self) -> None:
self.mw.col.set_wants_abort() self.mw.col.set_wants_abort()

View File

@ -14,6 +14,10 @@ export function bridgeLink(command: string, label: string): string {
return `<a href="javascript:bridgeCommand('${command}')">${label}</a>`; return `<a href="javascript:bridgeCommand('${command}')">${label}</a>`;
} }
export function bridgeCommandsAvailable(): boolean {
return !!window.bridgeCommand;
}
export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void { export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void {
window.bridgeCommand<T>(command, callback); window.bridgeCommand<T>(command, callback);
} }

View File

@ -3,10 +3,22 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import DeckOptionsPage from "../DeckOptionsPage.svelte"; import DeckOptionsPage from "../DeckOptionsPage.svelte";
import type { PageData } from "./$types"; import type { PageData } from "./$types";
import { bridgeCommand, bridgeCommandsAvailable } from "@tslib/bridgecommand";
export let data: PageData; export let data: PageData;
let page: DeckOptionsPage;
onMount(() => {
globalThis.$deckOptions = new Promise((resolve, _reject) => {
resolve(page);
});
if (bridgeCommandsAvailable()) {
bridgeCommand("deckOptionsReady");
}
});
</script> </script>
<DeckOptionsPage state={data.state} /> <DeckOptionsPage state={data.state} bind:this={page} />