Fix settings export: custom themes now travel with their full palette, fonts stay name-only

This commit is contained in:
sarah committed 2026-10-07 21:47:04 +02:00
1 parent efe6a3f948
commit ec1ff47c34
1 file changed
+28 -2
+28 -2
View File
@@ -459,8 +459,24 @@ def ExportSettings(Config: AppConfig, DestPath: Path) -> None:
file... applies to every other SaraSuite program"). A future SaraView/
SaraTag/etc. import would read the same [SaraSuite] section plus its
own top-level one, ignoring [SaraFem] — the same convention
ImportSettings below uses to ignore sections that aren't its own."""
Data = {"SaraSuite": asdict(_OwnSettings(Config)), "SaraFem": asdict(Config)}
ImportSettings below uses to ignore sections that aren't its own.
A custom (non-built-in) theme's actual palette rides along under
ThemeData (Bugs/Major: "Cannot export custom theme... theme can be
fully exported") — a theme is just a small local TOML file, nothing
stops it traveling with the export, unlike a font, which stays a name
only (the font itself needs installing some other way regardless of
what this file says)."""
OwnSettings = _OwnSettings(Config)
SharedData = asdict(OwnSettings)
if OwnSettings.Theme not in BuiltinThemes:
ThemeFile = ThemesDir / f"{OwnSettings.Theme}.toml"
if ThemeFile.exists():
try:
SharedData["ThemeData"] = toml.loads(ThemeFile.read_text()).get("Palette", {})
except toml.TomlDecodeError:
pass
Data = {"SaraSuite": SharedData, "SaraFem": asdict(Config)}
DestPath.write_text(toml.dumps(Data))
@@ -478,10 +494,20 @@ def ImportSettings(Config: AppConfig, SrcPath: Path) -> None:
SharedData = Data.get("SaraSuite")
if isinstance(SharedData, dict):
# Popped before the known-fields filter below (same reason as the
# SaraTag/SaraSortd/FolderIconBands nested data elsewhere here) —
# ThemeData isn't a SharedSettings field, it's the custom theme's
# actual palette, written out as that theme's own local file so the
# name being imported alongside it actually resolves to something.
ThemeData = SharedData.pop("ThemeData", None)
KnownSharedFields = {F for F in SharedSettings.__dataclass_fields__}
Filtered = {K: V for K, V in SharedData.items() if K in KnownSharedFields}
Merged = asdict(_OwnSettings(Config))
Merged.update(Filtered)
ImportedTheme = Merged.get("Theme")
if isinstance(ThemeData, dict) and ImportedTheme and ImportedTheme not in BuiltinThemes:
ThemesDir.mkdir(parents=True, exist_ok=True)
(ThemesDir / f"{ImportedTheme}.toml").write_text(toml.dumps({"Palette": ThemeData}))
SharedSettings(**Merged).Save()
OwnData = Data.get("SaraFem")