fix gamePath set null when closing page

This commit is contained in:
DismissedLight
2023-12-18 22:44:31 +08:00
parent 655d8a74af
commit 83cbc9bbe1
3 changed files with 24 additions and 24 deletions

View File

@@ -3,7 +3,7 @@
namespace Snap.Hutao.Control;
internal interface IScopedPageScopeReferenceTracker
internal interface IScopedPageScopeReferenceTracker : IDisposable
{
IServiceScope CreateScope();
}

View File

@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml;
using Snap.Hutao.Control;
using Snap.Hutao.Core.Windowing;
using Windows.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;
@@ -19,10 +20,10 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMax
private const int MinWidth = 1000;
private const int MinHeight = 600;
private readonly IServiceProvider serviceProvider;
private readonly WindowOptions windowOptions;
private readonly ILogger<MainWindow> logger;
private readonly TypedEventHandler<object, WindowEventArgs> closedEventHander;
private readonly TypedEventHandler<object, WindowSizeChangedEventArgs> sizeChangedEventHandler;
/// <summary>
/// 构造一个新的主窗体
@@ -31,15 +32,13 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMax
public MainWindow(IServiceProvider serviceProvider)
{
InitializeComponent();
this.serviceProvider = serviceProvider;
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), true);
this.InitializeController(serviceProvider);
logger = serviceProvider.GetRequiredService<ILogger<MainWindow>>();
closedEventHander = OnClosed;
sizeChangedEventHandler = OnSizeChanged;
Closed += closedEventHander;
SizeChanged += sizeChangedEventHandler;
}
/// <inheritdoc/>
@@ -54,10 +53,10 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMax
private void OnClosed(object sender, WindowEventArgs args)
{
logger.LogInformation("MainWindow Closed");
}
private void OnSizeChanged(object sender, WindowSizeChangedEventArgs args)
{
// The Closed event is raised before XamlRoot is unloaded.
using (serviceProvider.GetRequiredService<IScopedPageScopeReferenceTracker>())
{
// Thus we can eusure all viewmodels are disposed.
}
}
}

View File

@@ -16,6 +16,7 @@ internal static class StaticResource
private static readonly ApplicationDataCompositeValue DefaultResourceVersionMap = new()
{
// DO NOT MIDIFY THIS MAP
{ "AchievementIcon", 0 },
{ "AvatarCard", 0 },
{ "AvatarIcon", 0 },
@@ -47,29 +48,29 @@ internal static class StaticResource
{
{ "AchievementIcon", 1 },
{ "AvatarCard", 1 },
{ "AvatarIcon", 3 },
{ "AvatarIcon", 4 },
{ "Bg", 2 },
{ "ChapterIcon", 1 },
{ "ChapterIcon", 2 },
{ "CodexMonster", 0 },
{ "Costume", 1 },
{ "EmotionIcon", 1 },
{ "EquipIcon", 2 },
{ "GachaAvatarIcon", 2 },
{ "GachaAvatarImg", 2 },
{ "GachaEquipIcon", 2 },
{ "EmotionIcon", 2 },
{ "EquipIcon", 3 },
{ "GachaAvatarIcon", 3 },
{ "GachaAvatarImg", 3 },
{ "GachaEquipIcon", 3 },
{ "GcgCharAvatarIcon", 0 },
{ "IconElement", 2 },
{ "ItemIcon", 2 },
{ "ItemIcon", 3 },
{ "LoadingPic", 1 },
{ "MonsterIcon", 2 },
{ "MonsterSmallIcon", 1 },
{ "NameCardIcon", 1 },
{ "NameCardPic", 2 },
{ "NameCardIcon", 2 },
{ "NameCardPic", 3 },
{ "NameCardPicAlpha", 0 },
{ "Property", 1 },
{ "RelicIcon", 2 },
{ "Skill", 2 },
{ "Talent", 2 },
{ "RelicIcon", 3 },
{ "Skill", 3 },
{ "Talent", 3 },
};
public static void FulfillAll()