test only

This commit is contained in:
qhy040404
2024-06-13 13:35:55 +08:00
parent cc71aa9c82
commit c4ab6002f7
7 changed files with 66 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Core.Windowing.Abstraction;
using Snap.Hutao.Core.Windowing.NotifyIcon;
using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Service;
using Snap.Hutao.Win32;
using Snap.Hutao.Win32.Foundation;
@@ -99,10 +100,13 @@ internal sealed class XamlWindowController
private void OnWindowClosed(object sender, WindowEventArgs args)
{
IContentDialogFactory contentDialogFactory = serviceProvider.GetRequiredService<IContentDialogFactory>();
contentDialogFactory.CloseCurrentDialog();
if (XamlLifetime.ApplicationLaunchedWithNotifyIcon && !XamlLifetime.ApplicationExiting)
{
args.Handled = true;
window.Hide();
//args.Handled = true;
//window.Hide();
if (!IsNotifyIconVisible())
{

View File

@@ -18,6 +18,8 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
private readonly ITaskContext taskContext;
private readonly AppOptions appOptions;
private Microsoft.UI.Xaml.Controls.ContentDialog? currentDialog;
/// <inheritdoc/>
public async ValueTask<ContentDialogResult> CreateForConfirmAsync(string title, string content)
{
@@ -32,6 +34,8 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
RequestedTheme = appOptions.ElementTheme,
};
dialog.Closed += OnContentDialogClosed;
currentDialog = dialog;
return await dialog.ShowAsync();
}
@@ -50,6 +54,8 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
RequestedTheme = appOptions.ElementTheme,
};
dialog.Closed += OnContentDialogClosed;
currentDialog = dialog;
return await dialog.ShowAsync();
}
@@ -65,6 +71,8 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
RequestedTheme = appOptions.ElementTheme,
};
dialog.Closed += OnContentDialogClosed;
currentDialog = dialog;
return dialog;
}
@@ -75,6 +83,9 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
TContentDialog contentDialog = serviceProvider.CreateInstance<TContentDialog>(parameters);
contentDialog.XamlRoot = currentWindowReference.GetXamlRoot();
contentDialog.RequestedTheme = appOptions.ElementTheme;
contentDialog.Closed += OnContentDialogClosed;
currentDialog = contentDialog;
return contentDialog;
}
@@ -84,6 +95,25 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
TContentDialog contentDialog = serviceProvider.CreateInstance<TContentDialog>(parameters);
contentDialog.XamlRoot = currentWindowReference.GetXamlRoot();
contentDialog.RequestedTheme = appOptions.ElementTheme;
contentDialog.Closed += OnContentDialogClosed;
currentDialog = contentDialog;
return contentDialog;
}
public void CloseCurrentDialog()
{
currentDialog?.Hide();
}
public async ValueTask CloseCurrentDialogAsync()
{
await taskContext.SwitchToMainThreadAsync();
currentDialog?.Hide();
}
private void OnContentDialogClosed(Microsoft.UI.Xaml.Controls.ContentDialog sender, ContentDialogClosedEventArgs args)
{
currentDialog = null;
}
}

View File

@@ -40,4 +40,8 @@ internal interface IContentDialogFactory
ValueTask<TContentDialog> CreateInstanceAsync<TContentDialog>(params object[] parameters)
where TContentDialog : Microsoft.UI.Xaml.Controls.ContentDialog;
void CloseCurrentDialog();
ValueTask CloseCurrentDialogAsync();
}

View File

@@ -13,7 +13,7 @@ using Windows.Graphics;
namespace Snap.Hutao;
[HighQuality]
[Injection(InjectAs.Singleton)]
[Injection(InjectAs.Transient)]
internal sealed partial class LaunchGameWindow : Window,
IDisposable,
IXamlWindowExtendContentIntoTitleBar,

View File

@@ -14,7 +14,7 @@ namespace Snap.Hutao;
/// 主窗体
/// </summary>
[HighQuality]
[Injection(InjectAs.Singleton)]
[Injection(InjectAs.Transient)]
internal sealed partial class MainWindow : Window,
IXamlWindowExtendContentIntoTitleBar,
IXamlWindowRectPersisted,

View File

@@ -129,6 +129,11 @@
Header="Rename Desktop TestFolder"
IsClickEnabled="True"/>
<cwc:SettingsCard
Command="{Binding ReeeeeeecreateMainWindowCommand}"
Header="Infinitely Recreate Main Window"
IsClickEnabled="True"/>
<cwc:SettingsCard Header="Crash">
<StackPanel Orientation="Horizontal">
<Button Command="{Binding ExceptionCommand}" Content="Activate"/>

View File

@@ -172,4 +172,23 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel
string source = Path.Combine(desktop, "TestFolder");
DirectoryOperation.UnsafeRename(source, "TestFolder1");
}
[Command("ReeeeeeecreateMainWindowCommand")]
private async Task ReeeeeeecreateMainWindowAsync()
{
currentXamlWindowReference.Window?.Close();
currentXamlWindowReference.Window = null;
while (true)
{
MainWindow mainWindow = Ioc.Default.GetRequiredService<MainWindow>();
mainWindow.SwitchTo();
mainWindow.BringToForeground();
await Delay.FromMilliSeconds(2000).ConfigureAwait(true);
mainWindow.Hide();
mainWindow.Close();
}
}
}