From d423f07de9e688fc70caee7e8b992aab78999bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=81=D1=82=D1=80=D0=BE=D0=B2=20=D0=9C=D0=B8?= =?UTF-8?q?=D1=85=D0=B0=D0=B8=D0=BB=20=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=D0=B8=D1=87?= Date: Fri, 8 May 2026 13:08:32 +0300 Subject: [PATCH] fix/ToastNotificationHost-delay --- .../Views/ToastNotificationHost.axaml.cs | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/KeyKeeper/Views/ToastNotificationHost.axaml.cs b/src/KeyKeeper/Views/ToastNotificationHost.axaml.cs index 8291734..ce71e76 100644 --- a/src/KeyKeeper/Views/ToastNotificationHost.axaml.cs +++ b/src/KeyKeeper/Views/ToastNotificationHost.axaml.cs @@ -11,7 +11,7 @@ namespace KeyKeeper.Views public partial class ToastNotificationHost : UserControl { private CancellationTokenSource? _hideCancellation; - private Animation? _fadeOutAnimation; + private readonly Animation _fadeOutAnimation; public static readonly StyledProperty MessageProperty = AvaloniaProperty.Register(nameof(Message), string.Empty); @@ -44,15 +44,16 @@ namespace KeyKeeper.Views new KeyFrame { Cue = new Cue(0d), - Setters = { new Setter(OpacityProperty, 1.0) }, + Setters = { new Setter(OpacityProperty, 1.0) } }, new KeyFrame { Cue = new Cue(1d), - Setters = { new Setter(OpacityProperty, 0.0) }, + Setters = { new Setter(OpacityProperty, 0.0) } } } }; + Opacity = 0; } @@ -60,31 +61,21 @@ namespace KeyKeeper.Views { _hideCancellation?.Cancel(); _hideCancellation = new CancellationTokenSource(); + Message = message; Opacity = 1; - _ = HideAfterDelay(_hideCancellation.Token); } - private void FadeOut() - { - _fadeOutAnimation?.RunAsync(this); - } - - private async Task HideAfterDelay(CancellationToken cancellationToken) + private async Task HideAfterDelay(CancellationToken token) { try { - await Task.Delay(Duration, cancellationToken); - - if (!cancellationToken.IsCancellationRequested) - { - FadeOut(); - } + await Task.Delay(Duration, token); + await _fadeOutAnimation.RunAsync(this, token); } catch (TaskCanceledException) { - // caught } }