Add support for priority

Set default title to topic unique, as displayed in subscriptions list, if not provided
Increase toast timeout to 5 seconds
This commit is contained in:
Alexander Horner
2022-12-08 19:54:14 +00:00
parent d90ddc3be4
commit 7f73bd2cd1
5 changed files with 37 additions and 7 deletions

View File

@@ -54,7 +54,19 @@ namespace ntfysh_client
private void OnNotificationReceive(object sender, NotificationReceiveEventArgs e)
{
notifyIcon.ShowBalloonTip(3000, e.Title, e.Message, ToolTipIcon.Info);
ToolTipIcon priorityIcon = e.Priority switch
{
NotificationPriority.Max => ToolTipIcon.Error,
NotificationPriority.High => ToolTipIcon.Warning,
NotificationPriority.Default => ToolTipIcon.Info,
NotificationPriority.Low => ToolTipIcon.Info,
NotificationPriority.Min => ToolTipIcon.None,
_ => throw new ArgumentOutOfRangeException("Unknown priority received")
};
string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title;
notifyIcon.ShowBalloonTip(5000, finalTitle, e.Message, priorityIcon);
}
private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic)

View File

@@ -85,7 +85,7 @@ namespace ntfysh_client.Notifications
lines.RemoveAt(partialLineIndex);
//Process the full lines
foreach (string line in lines) ProcessMessage(line);
foreach (string line in lines) ProcessMessage(topic, line);
//Write back the partial line
mainBuffer.Clear();
@@ -189,7 +189,7 @@ namespace ntfysh_client.Notifications
lines.RemoveAt(partialLineIndex);
//Process the full lines
foreach (string line in lines) ProcessMessage(line);
foreach (string line in lines) ProcessMessage(topic, line);
//Write back the partial line
mainBuffer.Clear();
@@ -244,7 +244,7 @@ namespace ntfysh_client.Notifications
}
}
private void ProcessMessage(string message)
private void ProcessMessage(SubscribedTopic topic, string message)
{
#if DEBUG
Debug.WriteLine(message);
@@ -257,7 +257,7 @@ namespace ntfysh_client.Notifications
if (evt.Event == "message")
{
OnNotificationReceive?.Invoke(this, new NotificationReceiveEventArgs(evt.Title, evt.Message));
OnNotificationReceive?.Invoke(this, new NotificationReceiveEventArgs(topic, evt.Title ?? "", evt.Message, evt.Priority ?? NotificationPriority.Default));
}
}

View File

@@ -0,0 +1,11 @@
namespace ntfysh_client.Notifications
{
public enum NotificationPriority
{
Min = 1,
Low = 2,
Default = 3,
High = 4,
Max = 5
}
}

View File

@@ -4,13 +4,17 @@ namespace ntfysh_client.Notifications
{
public class NotificationReceiveEventArgs : EventArgs
{
public SubscribedTopic Sender { get; }
public string Title { get; }
public string Message { get; }
public NotificationPriority Priority { get; set; }
public NotificationReceiveEventArgs(string title, string message)
public NotificationReceiveEventArgs(SubscribedTopic sender, string title, string message, NotificationPriority priority)
{
Sender = sender;
Title = title;
Message = message;
Priority = priority;
}
}
}

View File

@@ -20,6 +20,9 @@ namespace ntfysh_client.Notifications
public string Message { get; set; } = null!;
[JsonProperty("title")]
public string Title { get; set; } = null!;
public string? Title { get; set; }
[JsonProperty("priority")]
public NotificationPriority? Priority { get; set; }
}
}