simplifying closing process
MODIFY
WalletWasabi.Gui/Behaviors/PredicateCloseBehavior.cs
WalletWasabi.Gui/Behaviors/PredicateCloseBehavior.cs
@@ -7,6 +7,7 @@ using System.ComponentModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text;
+using System.Threading.Tasks;
using WalletWasabi.Gui.Dialogs;
using WalletWasabi.Gui.ViewModels;
@@ -22,6 +23,8 @@ namespace WalletWasabi.Gui.Behaviors
public static readonly AvaloniaProperty<bool> CanCloseProperty =
AvaloniaProperty.Register<PredicateCloseBehavior, bool>(nameof(CanClose));
+ public Task DialogWindowTask = null;
+
public bool CanClose
{
get => GetValue(CanCloseProperty);
@@ -34,13 +37,11 @@ namespace WalletWasabi.Gui.Behaviors
_disposables = new CompositeDisposable
{
- Observable.FromEventPattern<CancelEventArgs>(AssociatedObject, nameof(AssociatedObject.Closing)).Subscribe(ev =>
+ Observable.FromEventPattern<CancelEventArgs>(AssociatedObject, nameof(AssociatedObject.Closing)).Subscribe(async ev =>
{
if(!CanClose)
{
ev.EventArgs.Cancel = true;
-
- MainWindowViewModel.Instance.ShowDialogAsync(new CannotCloseDialogViewModel()).GetAwaiter();
}
})
};

MODIFY
WalletWasabi.Gui/Dialogs/CannotCloseDialogViewModel.cs
WalletWasabi.Gui/Dialogs/CannotCloseDialogViewModel.cs
@@ -38,7 +38,7 @@ namespace WalletWasabi.Gui.Dialogs
{
_cancelTokenSource.Cancel();
// OK pressed.
- Close(true);
+ Close(false);
});
IsBusy = true;
@@ -51,6 +51,17 @@ namespace WalletWasabi.Gui.Dialogs
try
{
DateTime start = DateTime.Now;
+
+ while (!IsVisible) //waiting for the window to show. TODO: add OnShow ModalDialogViewModelBase.
+ {
+ //If this is not waited than ModalDialogViewModelBase.dialogCloseCompletionSource will throw NRF when Close(true) called
+ await Task.Delay(300);
+ if (DateTime.Now - start > TimeSpan.FromSeconds(10))
+ throw new InvalidOperationException("Window not opened");
+ }
+
+ start = DateTime.Now;
+
bool last = false;
while (!last)
{
@@ -67,14 +78,7 @@ namespace WalletWasabi.Gui.Dialogs
}
}
_cancelTokenSource.Cancel();
- Dispatcher.UIThread.Post(() =>
- {
- try
- {
- Global.QuitApplication();
- }
- catch (Exception) { }
- });
+ Close(true);
}
catch (Exception ex)
{

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -16,6 +16,8 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Crypto;
+using WalletWasabi.Gui.Dialogs;
+using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Helpers;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
@@ -357,7 +359,7 @@ namespace WalletWasabi.Gui
Logger.LogInfo($"{nameof(ChaumianClient)} is stopped.", nameof(Global));
}
- public static void QuitApplication()
+ public static async Task QuitApplicationAsync()
{
if (IsQuitPending) return;
IsQuitPending = true;
@@ -365,6 +367,10 @@ namespace WalletWasabi.Gui
{
if (ChaumianClient != null)
ChaumianClient.IsQuitPending = true;
+ bool successfulDequeue = false;
+ if (!MainWindowViewModel.Instance.CanClose)
+ successfulDequeue = await MainWindowViewModel.Instance.ShowDialogAsync(new CannotCloseDialogViewModel());
+ if (successfulDequeue || MainWindowViewModel.Instance.CanClose)
Application.Current.MainWindow.Close();
}
finally

simplifying closing process