diff --git a/StabilityMatrix.Avalonia/Extensions/NotificationLevelExtensions.cs b/StabilityMatrix.Avalonia/Extensions/NotificationLevelExtensions.cs new file mode 100644 index 00000000..fbb62e5a --- /dev/null +++ b/StabilityMatrix.Avalonia/Extensions/NotificationLevelExtensions.cs @@ -0,0 +1,20 @@ +using System; +using Avalonia.Controls.Notifications; +using StabilityMatrix.Core.Models.Settings; + +namespace StabilityMatrix.Avalonia.Extensions; + +public static class NotificationLevelExtensions +{ + public static NotificationType ToNotificationType(this NotificationLevel level) + { + return level switch + { + NotificationLevel.Information => NotificationType.Information, + NotificationLevel.Success => NotificationType.Success, + NotificationLevel.Warning => NotificationType.Warning, + NotificationLevel.Error => NotificationType.Error, + _ => throw new ArgumentOutOfRangeException(nameof(level), level, null) + }; + } +} diff --git a/StabilityMatrix.Core/Models/Settings/NotificationKey.cs b/StabilityMatrix.Core/Models/Settings/NotificationKey.cs index f57b8b25..00b6459f 100644 --- a/StabilityMatrix.Core/Models/Settings/NotificationKey.cs +++ b/StabilityMatrix.Core/Models/Settings/NotificationKey.cs @@ -9,16 +9,19 @@ namespace StabilityMatrix.Core.Models.Settings; /// [SuppressMessage("ReSharper", "InconsistentNaming")] [JsonConverter(typeof(StringJsonConverter))] -public record NotificationKey(string Value) : StringValue(Value) +public record NotificationKey(string Value) : StringValue(Value), IParsable { public NotificationOption DefaultOption { get; init; } + public NotificationLevel Level { get; init; } + public string? DisplayName { get; init; } public static NotificationKey Inference_PromptCompleted => new("Inference_PromptCompleted") { DefaultOption = NotificationOption.NativePush, + Level = NotificationLevel.Success, DisplayName = "Inference Prompt Completed" }; @@ -26,6 +29,7 @@ public record NotificationKey(string Value) : StringValue(Value) new("Download_Completed") { DefaultOption = NotificationOption.NativePush, + Level = NotificationLevel.Success, DisplayName = "Download Completed" }; @@ -33,6 +37,7 @@ public record NotificationKey(string Value) : StringValue(Value) new("Download_Failed") { DefaultOption = NotificationOption.NativePush, + Level = NotificationLevel.Error, DisplayName = "Download Failed" }; @@ -40,6 +45,7 @@ public record NotificationKey(string Value) : StringValue(Value) new("Download_Canceled") { DefaultOption = NotificationOption.NativePush, + Level = NotificationLevel.Warning, DisplayName = "Download Canceled" }; @@ -47,4 +53,20 @@ public record NotificationKey(string Value) : StringValue(Value) /// public override string ToString() => base.ToString(); + + /// + public static NotificationKey Parse(string s, IFormatProvider? provider) + { + return All[s]; + } + + /// + public static bool TryParse( + string? s, + IFormatProvider? provider, + [MaybeNullWhen(false)] out NotificationKey result + ) + { + return All.TryGetValue(s ?? "", out result); + } } diff --git a/StabilityMatrix.Core/Models/Settings/NotificationLevel.cs b/StabilityMatrix.Core/Models/Settings/NotificationLevel.cs new file mode 100644 index 00000000..6300508b --- /dev/null +++ b/StabilityMatrix.Core/Models/Settings/NotificationLevel.cs @@ -0,0 +1,9 @@ +namespace StabilityMatrix.Core.Models.Settings; + +public enum NotificationLevel +{ + Information, + Success, + Warning, + Error +}