From dec5ff0ff92800f91e5580a4dbeb48b592ecffb8 Mon Sep 17 00:00:00 2001 From: Luc Mcgrady Date: Fri, 26 Jun 2026 21:52:54 +0100 Subject: [PATCH 1/6] Save set values in config_json --- qt/aqt/mediasrv.py | 3 +++ qt/aqt/webview.py | 1 + rslib/src/backend/config.rs | 10 ++++++++-- ts/lib/components/Switch.svelte | 1 + ts/routes/preferences/+page.svelte | 14 ++++++++++---- ts/routes/preferences/+page.ts | 16 ++++++++++++++++ ts/routes/preferences/LabItem.svelte | 11 ++++++++++- ts/routes/preferences/json.ts | 21 +++++++++++++++++++++ 8 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 ts/routes/preferences/+page.ts create mode 100644 ts/routes/preferences/json.ts diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index c7f0d831cf1..3968c609fab 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -760,6 +760,9 @@ def save_custom_colours() -> bytes: # DeckConfigService "get_ignored_before_count", "get_retention_workload", + # ConfigService + "set_config_json", + "get_config_json", ] diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py index 1d55006ba5a..c7fd8165796 100644 --- a/qt/aqt/webview.py +++ b/qt/aqt/webview.py @@ -143,6 +143,7 @@ def _profileForPage(self, kind: AnkiWebViewKind) -> QWebEngineProfile: AnkiWebViewKind.IMPORT_ANKI_PACKAGE, AnkiWebViewKind.IMPORT_CSV, AnkiWebViewKind.IMPORT_LOG, + AnkiWebViewKind.PREFERENCES, ) global _profile_with_api_access, _profile_without_api_access diff --git a/rslib/src/backend/config.rs b/rslib/src/backend/config.rs index b6e81ce2ad7..3b731067472 100644 --- a/rslib/src/backend/config.rs +++ b/rslib/src/backend/config.rs @@ -57,8 +57,14 @@ impl From for StringKey { impl crate::services::ConfigService for Collection { fn get_config_json(&mut self, input: generic::String) -> Result { - let val: Option = self.get_config_optional(input.val.as_str()); - val.or_not_found(input.val) + let key = input.val.as_str(); + let val: Option = self.get_config_optional(key); + let default = match key { + "experimentalFeatures" => Some(serde_json::from_str("{}").unwrap()), + _ => None, + }; + val.or(default) + .or_not_found(key) .and_then(|v| serde_json::to_vec(&v).map_err(Into::into)) .map(Into::into) } diff --git a/ts/lib/components/Switch.svelte b/ts/lib/components/Switch.svelte index d48f46fb338..343cddf3baa 100644 --- a/ts/lib/components/Switch.svelte +++ b/ts/lib/components/Switch.svelte @@ -20,6 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html class:nightMode={$pageTheme.isDark} bind:checked={value} {disabled} + on:input /> diff --git a/ts/routes/preferences/+page.svelte b/ts/routes/preferences/+page.svelte index 6032d7bd502..471f80732f4 100644 --- a/ts/routes/preferences/+page.svelte +++ b/ts/routes/preferences/+page.svelte @@ -2,10 +2,14 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> -
@@ -17,13 +21,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -
diff --git a/ts/routes/preferences/+page.ts b/ts/routes/preferences/+page.ts new file mode 100644 index 00000000000..03d19aa0ee8 --- /dev/null +++ b/ts/routes/preferences/+page.ts @@ -0,0 +1,16 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +import { autoSavingPrefs } from "$lib/sveltelib/preferences"; +import type { PageLoad } from "./$types"; +import { getConfigJsonObject, setConfigJsonObject } from "./json"; + +const CONFIG_KEY = "experimentalFeatures"; + +export const load = (async () => { + const labPerfs = await autoSavingPrefs( + () => getConfigJsonObject(CONFIG_KEY), + ($config) => setConfigJsonObject(CONFIG_KEY, $config), + ); + + return { labPerfs }; +}) satisfies PageLoad; diff --git a/ts/routes/preferences/LabItem.svelte b/ts/routes/preferences/LabItem.svelte index 03aec37b06b..8514f339d75 100644 --- a/ts/routes/preferences/LabItem.svelte +++ b/ts/routes/preferences/LabItem.svelte @@ -4,16 +4,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -->