Prevent multiple instances, allow starting in tray, documentation edits and priority support #4
@@ -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)
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
11
ntfysh_client/Notifications/NotificationPriority.cs
Normal file
11
ntfysh_client/Notifications/NotificationPriority.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace ntfysh_client.Notifications
|
||||
{
|
||||
public enum NotificationPriority
|
||||
{
|
||||
Min = 1,
|
||||
Low = 2,
|
||||
Default = 3,
|
||||
High = 4,
|
||||
Max = 5
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user