diff --git a/windows/AppSettings.cs b/windows/AppSettings.cs new file mode 100644 index 0000000..d11c36a --- /dev/null +++ b/windows/AppSettings.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using System.Text.Json; + +namespace ClaudeCheckerWindows; + +public class AppSettings +{ + public string CookieStore { get; set; } = ""; + public string BurnHistory { get; set; } = ""; + public int RefreshInterval { get; set; } = 120; + public bool ShowInTaskbar { get; set; } = true; + public bool BetaChannel { get; set; } = false; + + private static readonly string FilePath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + "ClaudeChecker", "settings.json"); + + private static AppSettings? _instance; + public static AppSettings Default => _instance ??= Load(); + + private static AppSettings Load() + { + try + { + if (File.Exists(FilePath)) + return JsonSerializer.Deserialize(File.ReadAllText(FilePath)) ?? new(); + } + catch { } + return new(); + } + + public void Save() + { + try + { + Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!); + File.WriteAllText(FilePath, JsonSerializer.Serialize(this, + new JsonSerializerOptions { WriteIndented = true })); + } + catch { } + } +}