fix: 通过通知栏图标重复退出时报错

fix #7154
This commit is contained in:
uye
2023-12-12 15:45:37 +08:00
parent cfa92f367c
commit e0f9bddd1d
2 changed files with 28 additions and 4 deletions

View File

@@ -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)

View File

@@ -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
/// </summary>
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())