Browse Source

NotificationKey parsing and levels

pull/438/head
Ionite 10 months ago
parent
commit
59e0df2773
No known key found for this signature in database
  1. 20
      StabilityMatrix.Avalonia/Extensions/NotificationLevelExtensions.cs
  2. 24
      StabilityMatrix.Core/Models/Settings/NotificationKey.cs
  3. 9
      StabilityMatrix.Core/Models/Settings/NotificationLevel.cs

20
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)
};
}
}

24
StabilityMatrix.Core/Models/Settings/NotificationKey.cs

@ -9,16 +9,19 @@ namespace StabilityMatrix.Core.Models.Settings;
/// </summary> /// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "InconsistentNaming")]
[JsonConverter(typeof(StringJsonConverter<NotificationKey>))] [JsonConverter(typeof(StringJsonConverter<NotificationKey>))]
public record NotificationKey(string Value) : StringValue(Value) public record NotificationKey(string Value) : StringValue(Value), IParsable<NotificationKey>
{ {
public NotificationOption DefaultOption { get; init; } public NotificationOption DefaultOption { get; init; }
public NotificationLevel Level { get; init; }
public string? DisplayName { get; init; } public string? DisplayName { get; init; }
public static NotificationKey Inference_PromptCompleted => public static NotificationKey Inference_PromptCompleted =>
new("Inference_PromptCompleted") new("Inference_PromptCompleted")
{ {
DefaultOption = NotificationOption.NativePush, DefaultOption = NotificationOption.NativePush,
Level = NotificationLevel.Success,
DisplayName = "Inference Prompt Completed" DisplayName = "Inference Prompt Completed"
}; };
@ -26,6 +29,7 @@ public record NotificationKey(string Value) : StringValue(Value)
new("Download_Completed") new("Download_Completed")
{ {
DefaultOption = NotificationOption.NativePush, DefaultOption = NotificationOption.NativePush,
Level = NotificationLevel.Success,
DisplayName = "Download Completed" DisplayName = "Download Completed"
}; };
@ -33,6 +37,7 @@ public record NotificationKey(string Value) : StringValue(Value)
new("Download_Failed") new("Download_Failed")
{ {
DefaultOption = NotificationOption.NativePush, DefaultOption = NotificationOption.NativePush,
Level = NotificationLevel.Error,
DisplayName = "Download Failed" DisplayName = "Download Failed"
}; };
@ -40,6 +45,7 @@ public record NotificationKey(string Value) : StringValue(Value)
new("Download_Canceled") new("Download_Canceled")
{ {
DefaultOption = NotificationOption.NativePush, DefaultOption = NotificationOption.NativePush,
Level = NotificationLevel.Warning,
DisplayName = "Download Canceled" DisplayName = "Download Canceled"
}; };
@ -47,4 +53,20 @@ public record NotificationKey(string Value) : StringValue(Value)
/// <inheritdoc /> /// <inheritdoc />
public override string ToString() => base.ToString(); public override string ToString() => base.ToString();
/// <inheritdoc />
public static NotificationKey Parse(string s, IFormatProvider? provider)
{
return All[s];
}
/// <inheritdoc />
public static bool TryParse(
string? s,
IFormatProvider? provider,
[MaybeNullWhen(false)] out NotificationKey result
)
{
return All.TryGetValue(s ?? "", out result);
}
} }

9
StabilityMatrix.Core/Models/Settings/NotificationLevel.cs

@ -0,0 +1,9 @@
namespace StabilityMatrix.Core.Models.Settings;
public enum NotificationLevel
{
Information,
Success,
Warning,
Error
}
Loading…
Cancel
Save