diff --git a/src/MaaWpfGui/Services/TrayIcon.cs b/src/MaaWpfGui/Services/TrayIcon.cs index bfb145f368..893b6c9abf 100644 --- a/src/MaaWpfGui/Services/TrayIcon.cs +++ b/src/MaaWpfGui/Services/TrayIcon.cs @@ -107,7 +107,10 @@ namespace MaaWpfGui.Services private static void AppExit(object sender, EventArgs e) { - System.Windows.Application.Current.MainWindow?.Close(); + if (Instances.TaskQueueViewModel.ConfirmExit()) + { + System.Windows.Application.Current.Shutdown(); + } } private static void OnNotifyIconDoubleClick(object sender, EventArgs e) diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 30a37d7925..bd9083474e 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -173,10 +173,18 @@ namespace MaaWpfGui.ViewModels.UI public bool Running { get; set; } + public bool Closing { get; set; } + private readonly DispatcherTimer _timer = new DispatcherTimer(); - private bool ConfirmExit() + public bool ConfirmExit() { + if (Closing) + { + return false; + } + + Closing = true; if (Application.Current.IsShuttingDown()) { // allow close if application is shutting down @@ -195,8 +203,12 @@ namespace MaaWpfGui.ViewModels.UI return true; } - var window = Instances.MainWindowManager.GetWindowIfVisible(); - var result = MessageBoxHelper.ShowNative(window, LocalizationHelper.GetString("ConfirmExitText"), LocalizationHelper.GetString("ConfirmExitTitle"), "MAA", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No); + var result = MessageBoxHelper.Show( + LocalizationHelper.GetString("ConfirmExitText"), + LocalizationHelper.GetString("ConfirmExitTitle"), + MessageBoxButton.YesNo, + MessageBoxImage.Question); + Closing = false; return result == MessageBoxResult.Yes; } @@ -808,6 +820,15 @@ namespace MaaWpfGui.ViewModels.UI /// public async void LinkStart() { + Instances.TaskQueueViewModel.Running = true; + var i = 0; + while (true) + { + await Task.Delay(1000); + AddLog(i++.ToString()); + } + + return; Instances.SettingsViewModel.SetupSleepManagement(); if (!_runningState.GetIdle())