Add HideShowBehavior
MODIFY
WalletWasabi.Fluent/App.axaml.cs
WalletWasabi.Fluent/App.axaml.cs
@@ -74,14 +74,6 @@ namespace WalletWasabi.Fluent
}
base.OnFrameworkInitializationCompleted();
-
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- Services.SingleInstanceChecker.OtherInstanceStarted += (sender, args) =>
- {
- MainViewModel.Instance!.WindowState = WindowState.Normal; // Todo: Unhide, Show, BringToFront?
- };
- }
}
private void DesktopOnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)

ADD
WalletWasabi.Fluent/Behaviors/HideShowBehavior.cs
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using Avalonia;
+using Avalonia.Controls;
+using ReactiveUI;
+using WalletWasabi.Fluent.ViewModels;
+using WalletWasabi.Services;
+
+namespace WalletWasabi.Fluent.Behaviors
+{
+ public class HideShowBehavior : DisposingBehavior<Window>
+ {
+ protected override void OnAttached(CompositeDisposable disposables)
+ {
+ if (AssociatedObject is null)
+ {
+ return;
+ }
+
+ // On macOs the Hide/Show is a natural feature.
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ Observable
+ .FromEventPattern(Services.SingleInstanceChecker,
+ nameof(SingleInstanceChecker.OtherInstanceStarted))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(_ =>
+ {
+ if (AssociatedObject.WindowState == WindowState.Minimized)
+ {
+ AssociatedObject.WindowState = (WindowState)Enum.Parse(typeof(WindowState), Services.UiConfig.WindowState);
+ }
+
+ // Fixes: https://github.com/zkSNACKs/WalletWasabi/issues/6309
+ var temp = AssociatedObject.WindowState;
+ AssociatedObject.Show();
+ AssociatedObject.WindowState = temp;
+
+ AssociatedObject.BringIntoView();
+ })
+ .DisposeWith(disposables);
+ }
+
+ //TODO: we need the close button click only, external close request should not be cancelled.
+ Observable
+ .FromEventPattern<CancelEventArgs>(AssociatedObject, nameof(AssociatedObject.Closing))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(args =>
+ {
+ if (Services.UiConfig.HideOnClose)
+ {
+ args.EventArgs.Cancel = true;
+ AssociatedObject.Hide();
+ }
+ })
+ .DisposeWith(disposables);
+ }
+ }
+}

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -73,6 +73,7 @@ namespace WalletWasabi.Fluent.ViewModels
_searchPage.Initialise();
this.WhenAnyValue(x => x.WindowState)
+ .Where(x => x != WindowState.Minimized)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(windowState => Services.UiConfig.WindowState = windowState.ToString());

MODIFY
WalletWasabi.Fluent/Views/MainWindow.axaml
WalletWasabi.Fluent/Views/MainWindow.axaml
WindowState="{Binding WindowState, Mode=TwoWay}">
<i:Interaction.Behaviors>
<behaviors:RegisterNotificationHostBehavior />
+ <behaviors:HideShowBehavior />
</i:Interaction.Behaviors>
<Panel Margin="{Binding #MainWindow.OffScreenMargin}">

Add HideShowBehavior