add an appviewmodel and implementation to prevent shutdown.
MODIFY
WalletWasabi.Fluent/App.axaml
WalletWasabi.Fluent/App.axaml
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WalletWasabi.Fluent"
xmlns:models="using:WalletWasabi.Models"
- x:Class="WalletWasabi.Fluent.App">
+ xmlns:vm="using:WalletWasabi.Fluent.ViewModels"
+ x:DataType="vm:ApplicationViewModel"
+ x:CompileBindings="True"
+ x:Class="WalletWasabi.Fluent.App" CanShutdownProvider="{Binding .}">
<Application.DataTemplates>
<local:ViewLocator/>
<DataTemplate DataType="models:ErrorDescriptor" x:DataType="models:ErrorDescriptor">
<StyleInclude Source="avares://WalletWasabi.Fluent/Controls/StatusItem.axaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Controls/PrivacyContentControl.axaml" />
</Application.Styles>
- <NativeMenu.Menu>
- <NativeMenu>
- <NativeMenuItem Header="About Wasabi Wallet" Command="{Binding AboutCommand}" />
- </NativeMenu>
- </NativeMenu.Menu>
</Application>

MODIFY
WalletWasabi.Fluent/App.axaml.cs
WalletWasabi.Fluent/App.axaml.cs
@@ -4,9 +4,11 @@ using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Data;
using Avalonia.Markup.Xaml;
using ReactiveUI;
using WalletWasabi.Fluent.Behaviors;
+using WalletWasabi.Fluent.Providers;
using WalletWasabi.Fluent.ViewModels;
using WalletWasabi.Fluent.Views;
@@ -16,6 +18,12 @@ namespace WalletWasabi.Fluent
{
private Func<Task> _backendInitialiseAsync;
+ /// <summary>
+ /// Defines the <see cref="CanShutdownProvider"/> property.
+ /// </summary>/
+ public static readonly StyledProperty<ICanShutdownProvider?> CanShutdownProviderProperty =
+ AvaloniaProperty.Register<App, ICanShutdownProvider?>(nameof(CanShutdownProvider), null, defaultBindingMode: BindingMode.TwoWay);
+
public App()
{
Name = "Wasabi Wallet";
@@ -26,6 +34,12 @@ namespace WalletWasabi.Fluent
_backendInitialiseAsync = backendInitialiseAsync;
}
+ public ICanShutdownProvider? CanShutdownProvider
+ {
+ get => GetValue(CanShutdownProviderProperty);
+ set => SetValue(CanShutdownProviderProperty, value);
+ }
+
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
@@ -41,6 +55,8 @@ namespace WalletWasabi.Fluent
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
+ desktop.ShutdownRequested += DesktopOnShutdownRequested;
+
desktop.MainWindow = new MainWindow
{
DataContext = MainViewModel.Instance
@@ -58,5 +74,13 @@ namespace WalletWasabi.Fluent
base.OnFrameworkInitializationCompleted();
}
+
+ private void DesktopOnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
+ {
+ if (CanShutdownProvider is { } provider)
+ {
+ e.Cancel = !provider.CanShutdown();
+ }
+ }
}
}
\ No newline at end of file

add an appviewmodel and implementation to prevent shutdown.