simplify to have only one method
MODIFY
WalletWasabi.Fluent/CrashReport/ViewModels/CrashReportWindowViewModel.cs
WalletWasabi.Fluent/CrashReport/ViewModels/CrashReportWindowViewModel.cs
@@ -14,8 +14,8 @@ public class CrashReportWindowViewModel : ViewModelBase
public CrashReportWindowViewModel(SerializableException serializedException)
{
SerializedException = serializedException;
- CancelCommand = ReactiveCommand.Create(AppLifetimeHelper.Restart);
- NextCommand = ReactiveCommand.Create(AppLifetimeHelper.ForceShutdown);
+ CancelCommand = ReactiveCommand.Create(() => AppLifetimeHelper.Shutdown(withShutdownPrevention: false, restart: true));
+ NextCommand = ReactiveCommand.Create(() => AppLifetimeHelper.Shutdown(withShutdownPrevention: false, restart: false));
OpenGitHubRepoCommand = ReactiveCommand.CreateFromTask(async () => await IoHelpers.OpenBrowserAsync(AboutViewModel.UserSupportLink));

MODIFY
WalletWasabi.Fluent/Helpers/AppLifetimeHelper.cs
WalletWasabi.Fluent/Helpers/AppLifetimeHelper.cs
@@ -11,31 +11,6 @@ namespace WalletWasabi.Fluent.Helpers;
/// </summary>
public static class AppLifetimeHelper
{
- /// <summary>
- /// Attempts to restart the app without passing any program arguments.
- /// </summary>
- /// <remarks>
- /// This method is only functional on the published builds
- /// and not on debugging runs.
- /// </remarks>
- public static void Restart()
- {
- StartAppWithArgs();
- ForceShutdown();
- }
-
- /// <summary>
- /// Restarts the application with shutdown prevention.
- /// </summary>
- /// <remarks>
- /// This method is only functional on the published builds
- /// and not on debugging runs.
- /// </remarks>
- public static void RestartWithShutdownPrevention()
- {
- SafeShutdown(restart: true);
- }
-
/// <summary>
/// Attempts to start a new instance of the app with optional program arguments
/// </summary>
@@ -58,21 +33,31 @@ public static class AppLifetimeHelper
}
/// <summary>
- /// Attempts to shutdown the current instance of the app safely with shutdown prevention.
+ /// Shuts down the application safely, optionally shutdown prevention and restart can be requested.
/// </summary>
- public static void SafeShutdown(bool restart = false)
+ /// <remarks>
+ /// This method is only functional on the published builds
+ /// and not on debugging runs.
+ /// </remarks>
+ /// <param name="withShutdownPrevention">Enabled the shutdown prevention, so a dialog will pop until the shutdown can be done safely.</param>
+ /// <param name="restart">If true, the application will restart after shutdown.</param>
+ public static void Shutdown(bool withShutdownPrevention = true, bool restart = false)
{
- if (Application.Current?.DataContext is ApplicationViewModel app)
+ switch ((withShutdownPrevention, restart))
{
- app.Shutdown(restart);
- }
- }
+ case (true, true):
+ case (true, false):
+ (Application.Current?.DataContext as ApplicationViewModel)?.Shutdown(restart);
+ break;
- /// <summary>
- /// Attempts to shutdown the current instance of the app safely without shutdown prevention.
- /// </summary>
- public static void ForceShutdown()
- {
+ case (false, true):
+ StartAppWithArgs();
+ (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.Shutdown();
+ break;
+
+ case (false, false):
(Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.Shutdown();
+ break;
+ }
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/SearchBar/Settings/RestartViewModel.cs
WalletWasabi.Fluent/ViewModels/SearchBar/Settings/RestartViewModel.cs
@@ -9,7 +9,7 @@ public class RestartViewModel : ViewModelBase
public RestartViewModel(string message)
{
Message = message;
- RestartCommand = ReactiveCommand.Create(AppLifetimeHelper.RestartWithShutdownPrevention);
+ RestartCommand = ReactiveCommand.Create(() => AppLifetimeHelper.Shutdown(withShutdownPrevention: true, restart: true));
}
public string Message { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/SettingsPageViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/SettingsPageViewModel.cs
@@ -36,7 +36,7 @@ public partial class SettingsPageViewModel : DialogViewModelBase<Unit>
BitcoinTabSettings = new BitcoinTabSettingsViewModel();
AdvancedSettingsTab = new AdvancedSettingsTabViewModel();
- RestartCommand = ReactiveCommand.Create(AppLifetimeHelper.RestartWithShutdownPrevention);
+ RestartCommand = ReactiveCommand.Create(() => AppLifetimeHelper.Shutdown(withShutdownPrevention: true, restart: true));
NextCommand = CancelCommand;
}

MODIFY
WalletWasabi.Fluent/ViewModels/StatusIcon/StatusIconViewModel.cs
WalletWasabi.Fluent/ViewModels/StatusIcon/StatusIconViewModel.cs
@@ -43,7 +43,7 @@ public partial class StatusIconViewModel : IStatusIconViewModel, IDisposable
UpdateCommand = ReactiveCommand.Create(() =>
{
Services.UpdateManager.DoUpdateOnClose = true;
- AppLifetimeHelper.SafeShutdown();
+ AppLifetimeHelper.Shutdown();
});
AskMeLaterCommand = ReactiveCommand.Create(() => UpdateAvailable = false);

simplify to have only one method