From cd921890701d85257902d97f12f825a6a3760c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Cobe=C3=B1a=20Mori=C3=A1n?= Date: Mon, 27 Apr 2026 15:07:13 +0200 Subject: [PATCH 1/3] add initial implementation --- src/ViewModels/LauncherPage.cs | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index db5e0241b..91873c116 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Specialized; +using System.Threading; using System.Threading.Tasks; using Avalonia.Collections; using CommunityToolkit.Mvvm.ComponentModel; @@ -44,6 +46,7 @@ public LauncherPage() // New welcome page will clear the search filter before. Welcome.Instance.ClearSearchFilter(); + Notifications.CollectionChanged += Notifications_CollectionChanged; } public LauncherPage(RepositoryNode node, Repository repo) @@ -52,6 +55,11 @@ public LauncherPage(RepositoryNode node, Repository repo) _data = repo; } + ~LauncherPage() + { + Notifications.CollectionChanged -= Notifications_CollectionChanged; + } + public void ClearNotifications() { Notifications.Clear(); @@ -118,5 +126,33 @@ public void CancelPopup() private object _data = null; private Models.DirtyState _dirtyState = Models.DirtyState.None; private Popup _popup = null; + private CancellationTokenSource _clearNotificationsCancellationToken; + + private void Notifications_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Add) + { + _clearNotificationsCancellationToken?.Cancel(); + _clearNotificationsCancellationToken = new CancellationTokenSource(); + ClearNotificationsAutomatically(); + } + } + + private async void ClearNotificationsAutomatically() + { + try + { + await Task.Delay(TimeSpan.FromSeconds(5), _clearNotificationsCancellationToken.Token); + + if (!_clearNotificationsCancellationToken.Token.IsCancellationRequested) + { + Notifications.Clear(); + } + } + catch (TaskCanceledException) + { + // Ignore the exception if the task was canceled + } + } } } From c971022f80849d55a4ec64e26a090a8e3fc8f304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Cobe=C3=B1a=20Mori=C3=A1n?= Date: Mon, 27 Apr 2026 15:21:18 +0200 Subject: [PATCH 2/3] refactor --- src/ViewModels/LauncherPage.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index 91873c116..679cc2f7f 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -132,14 +132,15 @@ private void Notifications_CollectionChanged(object sender, NotifyCollectionChan { if (e.Action == NotifyCollectionChangedAction.Add) { - _clearNotificationsCancellationToken?.Cancel(); - _clearNotificationsCancellationToken = new CancellationTokenSource(); ClearNotificationsAutomatically(); } } private async void ClearNotificationsAutomatically() { + _clearNotificationsCancellationToken?.Cancel(); + _clearNotificationsCancellationToken = new CancellationTokenSource(); + try { await Task.Delay(TimeSpan.FromSeconds(5), _clearNotificationsCancellationToken.Token); From 38dc44ed9ec7b77fbf84fbd172fe5b4060fe8e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Cobe=C3=B1a=20Mori=C3=A1n?= Date: Mon, 27 Apr 2026 15:21:46 +0200 Subject: [PATCH 3/3] fix not every notification added is auto-cleared --- src/ViewModels/LauncherPage.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index 679cc2f7f..47e5fef1e 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -53,6 +53,8 @@ public LauncherPage(RepositoryNode node, Repository repo) { _node = node; _data = repo; + + Notifications.CollectionChanged += Notifications_CollectionChanged; } ~LauncherPage()