diff --git a/src/Snap.Hutao/Snap.Hutao/Control/ScopedPage.cs b/src/Snap.Hutao/Snap.Hutao/Control/ScopedPage.cs index 09332bdc..3efa4c37 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/ScopedPage.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/ScopedPage.cs @@ -5,6 +5,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Markup; using Microsoft.UI.Xaml.Navigation; +using Snap.Hutao.Core.Abstraction; using Snap.Hutao.Service.Navigation; using Snap.Hutao.View.Helper; using Snap.Hutao.ViewModel.Abstraction; @@ -53,9 +54,14 @@ internal class ScopedPage : Page { try { - IViewModel viewModel = pageScope.ServiceProvider.GetRequiredService(); - viewModel.CancellationToken = viewCancellationTokenSource.Token; - viewModel.DeferContentLoader = new DeferContentLoader(this); + TViewModel viewModel = pageScope.ServiceProvider.GetRequiredService(); + using (viewModel.DisposeLock.Enter()) + { + viewModel.IsViewDisposed = false; + viewModel.CancellationToken = viewCancellationTokenSource.Token; + viewModel.DeferContentLoader = new DeferContentLoader(this); + } + DataContext = viewModel; } catch (Exception ex) @@ -104,13 +110,15 @@ internal class ScopedPage : Page viewCancellationTokenSource.Cancel(); IViewModel viewModel = (IViewModel)DataContext; - // Wait to ensure viewmodel operation is completed - viewModel.DisposeLock.Wait(); - viewModel.IsViewDisposed = true; + using (viewModel.DisposeLock.Enter()) + { + // Wait to ensure viewmodel operation is completed + viewModel.IsViewDisposed = true; - // Dispose the scope - pageScope.Dispose(); - GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true); + // Dispose the scope + pageScope.Dispose(); + GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true); + } } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IPinnable.cs b/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IPinnable.cs index f5f82b02..954fc48c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IPinnable.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IPinnable.cs @@ -5,5 +5,5 @@ namespace Snap.Hutao.Core.Abstraction; internal interface IPinnable { - ref readonly TData GetPinnableReference(); + ref TData GetPinnableReference(); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IResurrectable.cs b/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IResurrectable.cs new file mode 100644 index 00000000..66304c1f --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/Abstraction/IResurrectable.cs @@ -0,0 +1,9 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Core.Abstraction; + +internal interface IResurrectable +{ + void Resurrect(); +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json b/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json index a5fb2a14..36a6b395 100644 --- a/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json +++ b/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Snap.Hutao": { "commandName": "MsixPackage", - "nativeDebugging": false, + "nativeDebugging": true, "doNotLaunchApp": false, "allowLocalNetworkLoopbackProperty": true }, diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs index 714cd624..ee75e694 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs @@ -100,6 +100,6 @@ internal sealed partial class LaunchGameShared [Command("HandleGamePathNullOrEmptyCommand")] private void HandleGamePathNullOrEmpty() { - navigationService.Navigate(INavigationAwaiter.Default); + navigationService.Navigate(INavigationAwaiter.Default, true); } } \ No newline at end of file