Restore $deckOptions (#3265)
* Restore $deckOptions * Avoid error in logs when using ./yarn dev or mobile clients (dae)
This commit is contained in:
parent
55d68c01d8
commit
fa47e905c5
@ -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,6 +54,9 @@ class DeckOptionsDialog(QDialog):
|
||||
self.setWindowTitle(
|
||||
without_unicode_isolation(tr.actions_options_for(val=self._deck["name"]))
|
||||
)
|
||||
|
||||
def _on_bridge_cmd(self, cmd: str) -> None:
|
||||
if cmd == "deckOptionsReady":
|
||||
gui_hooks.deck_options_did_load(self)
|
||||
|
||||
def reject(self) -> None:
|
||||
|
@ -14,6 +14,10 @@ export function bridgeLink(command: string, label: string): string {
|
||||
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 {
|
||||
window.bridgeCommand<T>(command, callback);
|
||||
}
|
||||
|
@ -3,10 +3,22 @@ Copyright: Ankitects Pty Ltd and contributors
|
||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import DeckOptionsPage from "../DeckOptionsPage.svelte";
|
||||
import type { PageData } from "./$types";
|
||||
import { bridgeCommand, bridgeCommandsAvailable } from "@tslib/bridgecommand";
|
||||
|
||||
export let data: PageData;
|
||||
let page: DeckOptionsPage;
|
||||
|
||||
onMount(() => {
|
||||
globalThis.$deckOptions = new Promise((resolve, _reject) => {
|
||||
resolve(page);
|
||||
});
|
||||
if (bridgeCommandsAvailable()) {
|
||||
bridgeCommand("deckOptionsReady");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<DeckOptionsPage state={data.state} />
|
||||
<DeckOptionsPage state={data.state} bind:this={page} />
|
||||
|
Loading…
Reference in New Issue
Block a user