Skip to content

Commit

Permalink
fix: properly handle dismissal
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Mar 21, 2024
1 parent b6b0404 commit 4349b26
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions Ui/NotificationProgressManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 4349b26

Please sign in to comment.