diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index 895ffee..ce77083 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -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) diff --git a/ntfysh_client/Notifications/NotificationListener.cs b/ntfysh_client/Notifications/NotificationListener.cs index ef39467..f0acaa6 100644 --- a/ntfysh_client/Notifications/NotificationListener.cs +++ b/ntfysh_client/Notifications/NotificationListener.cs @@ -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)); } } diff --git a/ntfysh_client/Notifications/NotificationPriority.cs b/ntfysh_client/Notifications/NotificationPriority.cs new file mode 100644 index 0000000..cf82d9c --- /dev/null +++ b/ntfysh_client/Notifications/NotificationPriority.cs @@ -0,0 +1,11 @@ +namespace ntfysh_client.Notifications +{ + public enum NotificationPriority + { + Min = 1, + Low = 2, + Default = 3, + High = 4, + Max = 5 + } +} \ No newline at end of file diff --git a/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs index 6590e67..d87363d 100644 --- a/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs +++ b/ntfysh_client/Notifications/NotificationReceiveEventArgs.cs @@ -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; } } } \ No newline at end of file diff --git a/ntfysh_client/Notifications/NtfyEvent.cs b/ntfysh_client/Notifications/NtfyEvent.cs index 6cada12..de54962 100644 --- a/ntfysh_client/Notifications/NtfyEvent.cs +++ b/ntfysh_client/Notifications/NtfyEvent.cs @@ -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; } } } \ No newline at end of file