using System.Text.Json.Serialization; namespace StabilityMatrix.Core.Models.Settings; public class Settings { public int? Version { get; set; } = 1; public bool FirstLaunchSetupComplete { get; set; } public string? Theme { get; set; } = "Dark"; public List InstalledPackages { get; set; } = new(); [JsonPropertyName("ActiveInstalledPackage")] public Guid? ActiveInstalledPackageId { get; set; } /// /// The first installed package matching the /// or null if no matching package /// [JsonIgnore] public InstalledPackage? ActiveInstalledPackage { get => ActiveInstalledPackageId == null ? null : InstalledPackages.FirstOrDefault(x => x.Id == ActiveInstalledPackageId); set => ActiveInstalledPackageId = value?.Id; } public bool HasSeenWelcomeNotification { get; set; } public List? PathExtensions { get; set; } public string? WebApiHost { get; set; } public string? WebApiPort { get; set; } // UI states public bool ModelBrowserNsfwEnabled { get; set; } public bool IsNavExpanded { get; set; } public bool IsImportAsConnected { get; set; } public SharedFolderType? SharedFolderVisibleCategories { get; set; } = SharedFolderType.StableDiffusion | SharedFolderType.Lora | SharedFolderType.LyCORIS; public WindowSettings? WindowSettings { get; set; } public ModelSearchOptions? ModelSearchOptions { get; set; } public bool RemoveFolderLinksOnShutdown { get; set; } public bool IsDiscordRichPresenceEnabled { get; set; } public Dictionary? EnvironmentVariables { get; set; } public HashSet? InstalledModelHashes { get; set; } = new(); public float AnimationScale { get; set; } = 1.0f; public void RemoveInstalledPackageAndUpdateActive(InstalledPackage package) { RemoveInstalledPackageAndUpdateActive(package.Id); } public void RemoveInstalledPackageAndUpdateActive(Guid id) { InstalledPackages.RemoveAll(x => x.Id == id); UpdateActiveInstalledPackage(); } /// /// Update ActiveInstalledPackage if not valid /// uses first package or null if no packages /// public void UpdateActiveInstalledPackage() { // Empty packages - set to null if (InstalledPackages.Count == 0) { ActiveInstalledPackageId = null; } // Active package is not in package - set to first package else if (InstalledPackages.All(x => x.Id != ActiveInstalledPackageId)) { ActiveInstalledPackageId = InstalledPackages[0].Id; } } }