From 031cf77c2724389c3df12e430261421d1171497c Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Wed, 5 Jun 2024 19:09:57 +0800 Subject: [PATCH] refine LaunchGameAction --- .../Core/LifeCycle/AppActivation.cs | 38 +++++++++++-------- .../Core/Windowing/WindowExtension.cs | 3 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs index fb9be880..588c061b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs @@ -96,25 +96,31 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi await taskContext.SwitchToMainThreadAsync(); - if (currentWindowReference.Window is null) + switch (currentWindowReference.Window) { - currentWindowReference.Window = serviceProvider.GetRequiredService(); - return; - } + case null: + LaunchGameWindow launchGameWindow = serviceProvider.GetRequiredService(); + currentWindowReference.Window = launchGameWindow; - if (currentWindowReference.Window is MainWindow) - { - await serviceProvider - .GetRequiredService() - .NavigateAsync(INavigationAwaiter.Default, true) - .ConfigureAwait(false); + launchGameWindow.SwitchTo(); + launchGameWindow.BringToForeground(); + return; - return; - } - else - { - // We have a non-Main Window, just exit current process anyway - Process.GetCurrentProcess().Kill(); + case MainWindow: + await serviceProvider + .GetRequiredService() + .NavigateAsync(INavigationAwaiter.Default, true) + .ConfigureAwait(false); + return; + + case LaunchGameWindow currentLaunchGameWindow: + currentLaunchGameWindow.SwitchTo(); + currentLaunchGameWindow.BringToForeground(); + return; + + default: + Process.GetCurrentProcess().Kill(); + return; } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs index 89c48c77..19262af0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs @@ -63,7 +63,8 @@ internal static class WindowExtension { ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_SHOW); } - else if (IsIconic(hwnd)) + + if (IsIconic(hwnd)) { ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_RESTORE); }