using System.Text.Json; namespace LehrerApp.Desktop.Services; /// Systemvorgabe folgt (bisheriges, /// unverändertes Verhalten); Hell/Dunkel erzwingen die jeweilige Variante unabhängig vom /// Betriebssystem. public enum AppTheme { System, Light, Dark } internal sealed class AppearanceSettingsConfig { public AppTheme Theme { get; set; } = AppTheme.System; } /// Merkt sich die gewählte Darstellung (12.4) über Sitzungen hinweg. public sealed class AppearanceSettingsService { private readonly string _configPath; public AppearanceSettingsService(string appDataPath) => _configPath = Path.Combine(appDataPath, "appearancesettings.json"); public AppTheme Load() { try { if (File.Exists(_configPath)) return JsonSerializer.Deserialize(File.ReadAllText(_configPath)) ?.Theme ?? AppTheme.System; } catch { /* beschädigte Konfiguration -> Systemvorgabe */ } return AppTheme.System; } public void Save(AppTheme theme) => File.WriteAllText(_configPath, JsonSerializer.Serialize(new AppearanceSettingsConfig { Theme = theme })); } // ComboBox-Anzeige: deutsche Beschriftung statt des rohen Enum-Namens (etabliertes Muster, siehe // z.B. NiveauDisplay/GradeCategoryDisplay). public static class AppThemeDisplay { public static string Label(AppTheme theme) => theme switch { AppTheme.Light => "Hell", AppTheme.Dark => "Dunkel", _ => "Systemvorgabe", }; public static string[] Options { get; } = Enum.GetValues().Select(Label).ToArray(); public static AppTheme FromLabel(string? label) => Enum.GetValues().FirstOrDefault(t => Label(t) == label, AppTheme.System); }