fix exit crashing

This commit is contained in:
Lightczx
2024-05-13 16:33:12 +08:00
parent 38e152befd
commit d3acbcde24
5 changed files with 10 additions and 16 deletions

View File

@@ -50,8 +50,6 @@ public sealed partial class App : Application
/// <param name="serviceProvider">服务提供器</param>
public App(IServiceProvider serviceProvider)
{
// DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
// Load app resource
InitializeComponent();
activation = serviceProvider.GetRequiredService<IActivation>();
@@ -61,6 +59,14 @@ public sealed partial class App : Application
this.serviceProvider = serviceProvider;
}
public bool IsExiting { get; private set; }
public new void Exit()
{
IsExiting = true;
base.Exit();
}
/// <inheritdoc/>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{

View File

@@ -1,7 +1,6 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.UI.WindowsAndMessaging;

View File

@@ -136,7 +136,7 @@ internal sealed class XamlWindowController
private void OnWindowClosed(object sender, WindowEventArgs args)
{
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true))
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true) && !serviceProvider.GetRequiredService<App>().IsExiting)
{
args.Handled = true;
window.Hide();

View File

@@ -29,8 +29,6 @@ internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMi
InitializeComponent();
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), SettingKeys.WindowRect);
this.InitializeController(serviceProvider);
Closed += OnClosed;
}
/// <inheritdoc/>
@@ -42,13 +40,4 @@ internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMi
pInfo.ptMinTrackSize.x = (int)Math.Max(MinWidth * scalingFactor, pInfo.ptMinTrackSize.x);
pInfo.ptMinTrackSize.y = (int)Math.Max(MinHeight * scalingFactor, pInfo.ptMinTrackSize.y);
}
private void OnClosed(object sender, WindowEventArgs args)
{
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true))
{
args.Handled = true;
this.Hide();
}
}
}

View File

@@ -2,7 +2,7 @@
"profiles": {
"Snap.Hutao": {
"commandName": "MsixPackage",
"nativeDebugging": false,
"nativeDebugging": true,
"doNotLaunchApp": false,
"allowLocalNetworkLoopbackProperty": true
},