From 4349b26c4195e788d8fbfb6e7520f6bc1dfc7792 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 20 Mar 2024 20:12:42 -0400 Subject: [PATCH] fix: properly handle dismissal --- Ui/NotificationProgressManager.cs | 33 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Ui/NotificationProgressManager.cs b/Ui/NotificationProgressManager.cs index 84ac00d..770437a 100644 --- a/Ui/NotificationProgressManager.cs +++ b/Ui/NotificationProgressManager.cs @@ -55,32 +55,37 @@ internal void Update() { this.Notifications[task.TaskId] = notif; } - UpdateNotif(notif, task); - - if (task.State.IsDone()) { + var state = UpdateNotif(notif, task); + if (state.IsDone()) { this.Notifications.Remove(task.TaskId); } } } - private static void UpdateNotif(IActiveNotification notif, DownloadTask task) { - notif.Content = task.StateDataMax == 0 - ? $"{task.State.Name()} ({task.StateData:N0}" - : $"{task.State.Name()} ({task.StateData:N0} / {task.StateDataMax:N0})"; - notif.Progress = task.StateDataMax == 0 + private static State UpdateNotif(IActiveNotification notif, DownloadTask task) { + var state = task.State; + var sData = task.StateData; + var sMax = task.StateDataMax; + + notif.Content = sMax == 0 + ? $"{state.Name()} ({sData:N0}" + : $"{state.Name()} ({sData:N0} / {sMax:N0})"; + notif.Progress = sMax == 0 ? 0 - : (float)task.StateData / task.StateDataMax; + : (float) sData / sMax; - if (!task.State.IsDone()) { - return; + if (!state.IsDone()) { + return state; } - notif.HardExpiry = DateTime.UtcNow + TimeSpan.FromSeconds(task.State == State.Errored ? 5 : 3); - notif.Type = task.State switch { + notif.InitialDuration = TimeSpan.FromSeconds(state == State.Errored ? 5 : 3); + notif.Type = state switch { State.Finished => NotificationType.Success, State.Cancelled => NotificationType.Warning, State.Errored => NotificationType.Error, _ => NotificationType.Info, }; + + return state; } -} \ No newline at end of file +}