From e0f9bddd1dd03efcb706e6238097c90de8fe8d24 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:45:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=9A=E8=BF=87=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A0=8F=E5=9B=BE=E6=A0=87=E9=87=8D=E5=A4=8D=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #7154 --- src/MaaWpfGui/Services/TrayIcon.cs | 5 +++- .../ViewModels/UI/TaskQueueViewModel.cs | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) 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())