mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00

* Prevent memory leak * Fix deck option changes not detected until focus is lost * Accurately determine if there are any pending changes This makes it so that the confirmation dialog appears when it should, and not when it shouldn't.
37 lines
1.1 KiB
Svelte
37 lines
1.1 KiB
Svelte
<!--
|
|
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 { commitEditing } from "../lib";
|
|
import type { PageData } from "./$types";
|
|
import { bridgeCommand, bridgeCommandsAvailable } from "@tslib/bridgecommand";
|
|
|
|
export let data: PageData;
|
|
let page: DeckOptionsPage;
|
|
|
|
globalThis.anki ||= {};
|
|
globalThis.anki.deckOptionsPendingChanges = async (): Promise<void> => {
|
|
await commitEditing();
|
|
if (bridgeCommandsAvailable()) {
|
|
if (data.state.isModified()) {
|
|
bridgeCommand("confirmDiscardChanges");
|
|
} else {
|
|
bridgeCommand("_close");
|
|
}
|
|
}
|
|
};
|
|
|
|
onMount(() => {
|
|
globalThis.$deckOptions = new Promise((resolve, _reject) => {
|
|
resolve(page);
|
|
});
|
|
if (bridgeCommandsAvailable()) {
|
|
bridgeCommand("deckOptionsReady");
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<DeckOptionsPage state={data.state} bind:this={page} />
|