mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-18 22:36:30 +03:00
fix/ToastNotificationHost-delay
This commit is contained in:
@@ -11,7 +11,7 @@ namespace KeyKeeper.Views
|
|||||||
public partial class ToastNotificationHost : UserControl
|
public partial class ToastNotificationHost : UserControl
|
||||||
{
|
{
|
||||||
private CancellationTokenSource? _hideCancellation;
|
private CancellationTokenSource? _hideCancellation;
|
||||||
private Animation? _fadeOutAnimation;
|
private readonly Animation _fadeOutAnimation;
|
||||||
|
|
||||||
public static readonly StyledProperty<string> MessageProperty =
|
public static readonly StyledProperty<string> MessageProperty =
|
||||||
AvaloniaProperty.Register<ToastNotificationHost, string>(nameof(Message), string.Empty);
|
AvaloniaProperty.Register<ToastNotificationHost, string>(nameof(Message), string.Empty);
|
||||||
@@ -44,15 +44,16 @@ namespace KeyKeeper.Views
|
|||||||
new KeyFrame
|
new KeyFrame
|
||||||
{
|
{
|
||||||
Cue = new Cue(0d),
|
Cue = new Cue(0d),
|
||||||
Setters = { new Setter(OpacityProperty, 1.0) },
|
Setters = { new Setter(OpacityProperty, 1.0) }
|
||||||
},
|
},
|
||||||
new KeyFrame
|
new KeyFrame
|
||||||
{
|
{
|
||||||
Cue = new Cue(1d),
|
Cue = new Cue(1d),
|
||||||
Setters = { new Setter(OpacityProperty, 0.0) },
|
Setters = { new Setter(OpacityProperty, 0.0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Opacity = 0;
|
Opacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,31 +61,21 @@ namespace KeyKeeper.Views
|
|||||||
{
|
{
|
||||||
_hideCancellation?.Cancel();
|
_hideCancellation?.Cancel();
|
||||||
_hideCancellation = new CancellationTokenSource();
|
_hideCancellation = new CancellationTokenSource();
|
||||||
|
|
||||||
Message = message;
|
Message = message;
|
||||||
Opacity = 1;
|
Opacity = 1;
|
||||||
|
|
||||||
_ = HideAfterDelay(_hideCancellation.Token);
|
_ = HideAfterDelay(_hideCancellation.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FadeOut()
|
private async Task HideAfterDelay(CancellationToken token)
|
||||||
{
|
|
||||||
_fadeOutAnimation?.RunAsync(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HideAfterDelay(CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Delay(Duration, cancellationToken);
|
await Task.Delay(Duration, token);
|
||||||
|
await _fadeOutAnimation.RunAsync(this, token);
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
FadeOut();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException)
|
||||||
{
|
{
|
||||||
// caught
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user