From 83cbc9bbe1710c9c8334d4b7bf39ea77bb685b7c Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Mon, 18 Dec 2023 22:44:31 +0800 Subject: [PATCH] fix gamePath set null when closing page --- .../IScopedPageScopeReferenceTracker.cs | 2 +- src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs | 19 +++++++------ .../ViewModel/Guide/StaticResource.cs | 27 ++++++++++--------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Control/IScopedPageScopeReferenceTracker.cs b/src/Snap.Hutao/Snap.Hutao/Control/IScopedPageScopeReferenceTracker.cs index 288187f6..49854e9b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/IScopedPageScopeReferenceTracker.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/IScopedPageScopeReferenceTracker.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Control; -internal interface IScopedPageScopeReferenceTracker +internal interface IScopedPageScopeReferenceTracker : IDisposable { IServiceScope CreateScope(); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs index 2e720421..37d85da2 100644 --- a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs @@ -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 logger; + private readonly TypedEventHandler closedEventHander; - private readonly TypedEventHandler sizeChangedEventHandler; /// /// 构造一个新的主窗体 @@ -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>(); closedEventHander = OnClosed; - sizeChangedEventHandler = OnSizeChanged; Closed += closedEventHander; - SizeChanged += sizeChangedEventHandler; } /// @@ -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()) + { + // Thus we can eusure all viewmodels are disposed. + } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Guide/StaticResource.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Guide/StaticResource.cs index a23fe735..5175aa2d 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Guide/StaticResource.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Guide/StaticResource.cs @@ -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()