mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
launch game
This commit is contained in:
@@ -41,7 +41,7 @@ public sealed partial class App : Application
|
||||
""";
|
||||
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IActivation activation;
|
||||
private readonly IAppActivation activation;
|
||||
private readonly ILogger<App> logger;
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +52,7 @@ public sealed partial class App : Application
|
||||
{
|
||||
// Load app resource
|
||||
InitializeComponent();
|
||||
activation = serviceProvider.GetRequiredService<IActivation>();
|
||||
activation = serviceProvider.GetRequiredService<IAppActivation>();
|
||||
logger = serviceProvider.GetRequiredService<ILogger<App>>();
|
||||
serviceProvider.GetRequiredService<ExceptionRecorder>().Record(this);
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace Snap.Hutao.Core.LifeCycle;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton, typeof(IActivation))]
|
||||
[Injection(InjectAs.Singleton, typeof(IAppActivation))]
|
||||
[SuppressMessage("", "CA1001")]
|
||||
internal sealed partial class Activation : IActivation, IDisposable
|
||||
internal sealed partial class AppActivation : IAppActivation, IAppActivationActionHandlersAccess, IDisposable
|
||||
{
|
||||
public const string Action = nameof(Action);
|
||||
public const string Uid = nameof(Uid);
|
||||
@@ -74,6 +74,36 @@ internal sealed partial class Activation : IActivation, IDisposable
|
||||
activateSemaphore.Dispose();
|
||||
}
|
||||
|
||||
public async ValueTask HandleLaunchGameActionAsync(string? uid = null)
|
||||
{
|
||||
serviceProvider
|
||||
.GetRequiredService<IMemoryCache>()
|
||||
.Set(ViewModel.Game.LaunchGameViewModel.DesiredUid, uid);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
if (currentWindowReference.Window is null)
|
||||
{
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentWindowReference.Window is MainWindow)
|
||||
{
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a non-Main Window, just exit current process anyway
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
|
||||
private void NotificationActivate(ToastNotificationActivatedEventArgsCompat args)
|
||||
{
|
||||
ToastArguments toastArgs = ToastArguments.Parse(args.Argument);
|
||||
@@ -138,7 +168,7 @@ internal sealed partial class Activation : IActivation, IDisposable
|
||||
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
|
||||
{
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
serviceProvider.GetRequiredService<GuideWindow>();
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<GuideWindow>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -155,7 +185,7 @@ internal sealed partial class Activation : IActivation, IDisposable
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
serviceProvider.GetRequiredService<MainWindow>();
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<MainWindow>();
|
||||
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
|
||||
@@ -252,34 +282,4 @@ internal sealed partial class Activation : IActivation, IDisposable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask HandleLaunchGameActionAsync(string? uid = null)
|
||||
{
|
||||
serviceProvider
|
||||
.GetRequiredService<IMemoryCache>()
|
||||
.Set(ViewModel.Game.LaunchGameViewModel.DesiredUid, uid);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
if (currentWindowReference.Window is null)
|
||||
{
|
||||
serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentWindowReference.Window is MainWindow)
|
||||
{
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a non-Main Window, just exit current process anyway
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,14 @@
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
/// <summary>
|
||||
/// 激活
|
||||
/// </summary>
|
||||
internal interface IActivation
|
||||
internal interface IAppActivation
|
||||
{
|
||||
void Activate(HutaoActivationArguments args);
|
||||
|
||||
void PostInitialization();
|
||||
}
|
||||
|
||||
internal interface IAppActivationActionHandlersAccess
|
||||
{
|
||||
ValueTask HandleLaunchGameActionAsync(string? uid = null);
|
||||
}
|
||||
@@ -16,6 +16,6 @@ internal sealed partial class PrivateNamedPipeMessageDispatcher
|
||||
return;
|
||||
}
|
||||
|
||||
serviceProvider.GetRequiredService<IActivation>().Activate(args);
|
||||
serviceProvider.GetRequiredService<IAppActivation>().Activate(args);
|
||||
}
|
||||
}
|
||||
@@ -37,14 +37,30 @@
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal"
|
||||
Spacing="2">
|
||||
<AppBarButton
|
||||
Command="{Binding ShowMainWindowCommand}"
|
||||
Icon="{shcm:BitmapIcon Source=ms-appx:///Assets/Logo.ico}"
|
||||
Label="{shcm:ResourceString Name=CoreWindowingNotifyIconViewLabel}"/>
|
||||
<AppBarButton
|
||||
Command="{Binding ExitCommand}"
|
||||
Icon="{shcm:FontIcon Glyph=}"
|
||||
Label="{shcm:ResourceString Name=CoreWindowingNotifyIconExitLabel}"/>
|
||||
<AppBarButton Command="{Binding ShowWindowCommand}" Label="{shcm:ResourceString Name=CoreWindowingNotifyIconViewLabel}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Height="20"
|
||||
Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
<AppBarButton Command="{Binding LaunchGameCommand}" Label="{shcm:ResourceString Name=CoreWindowingNotifyIconLaunchGameLabel}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Height="20"
|
||||
Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
<AppBarButton Command="{Binding ExitCommand}" Label="{shcm:ResourceString Name=CoreWindowingNotifyIconExitLabel}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Height="20"
|
||||
Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -36,7 +36,6 @@ internal sealed class XamlWindowController
|
||||
this.options = options;
|
||||
this.serviceProvider = serviceProvider;
|
||||
|
||||
serviceProvider.GetRequiredService<ICurrentXamlWindowReference>().Window = window;
|
||||
subclass = new(window, options);
|
||||
windowNonRudeHWND = new(options.Hwnd);
|
||||
|
||||
@@ -140,18 +139,20 @@ internal sealed class XamlWindowController
|
||||
{
|
||||
args.Handled = true;
|
||||
window.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveOrSkipWindowSize();
|
||||
subclass?.Dispose();
|
||||
windowNonRudeHWND?.Dispose();
|
||||
|
||||
ICurrentXamlWindowReference currentXamlWindowReference = serviceProvider.GetRequiredService<ICurrentXamlWindowReference>();
|
||||
if (currentXamlWindowReference.Window == window)
|
||||
{
|
||||
currentXamlWindowReference.Window = default!;
|
||||
}
|
||||
|
||||
GC.Collect(GC.MaxGeneration);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveOrSkipWindowSize();
|
||||
subclass?.Dispose();
|
||||
windowNonRudeHWND?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,8 +195,11 @@
|
||||
<data name="CoreWindowingNotifyIconExitLabel" xml:space="preserve">
|
||||
<value>退出</value>
|
||||
</data>
|
||||
<data name="CoreWindowingNotifyIconLaunchGameLabel" xml:space="preserve">
|
||||
<value>启动游戏</value>
|
||||
</data>
|
||||
<data name="CoreWindowingNotifyIconViewLabel" xml:space="preserve">
|
||||
<value>主界面</value>
|
||||
<value>窗口</value>
|
||||
</data>
|
||||
<data name="CoreWindowThemeDark" xml:space="preserve">
|
||||
<value>深色</value>
|
||||
|
||||
@@ -77,8 +77,8 @@ internal sealed partial class DailyNoteNotificationOperation
|
||||
.AddAttributionText(attribution)
|
||||
.AddButton(new ToastButton()
|
||||
.SetContent(SH.ServiceDailyNoteNotifierActionLaunchGameButton)
|
||||
.AddArgument(Activation.Action, Activation.LaunchGame)
|
||||
.AddArgument(Activation.Uid, entry.Uid))
|
||||
.AddArgument(AppActivation.Action, AppActivation.LaunchGame)
|
||||
.AddArgument(AppActivation.Uid, entry.Uid))
|
||||
.AddButton(new ToastButtonDismiss(SH.ServiceDailyNoteNotifierActionLaunchGameDismiss));
|
||||
|
||||
if (options.IsReminderNotification)
|
||||
|
||||
@@ -112,7 +112,7 @@ internal sealed partial class AchievementViewModel : Abstraction.ViewModel, INav
|
||||
{
|
||||
if (await Initialization.Task.ConfigureAwait(false))
|
||||
{
|
||||
if (data.Data is Activation.ImportUIAFFromClipboard)
|
||||
if (data.Data is AppActivation.ImportUIAFFromClipboard)
|
||||
{
|
||||
await ImportUIAFFromClipboardAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace Snap.Hutao.ViewModel;
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class NotifyIconViewModel : ObservableObject
|
||||
{
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
private readonly ICurrentXamlWindowReference currentXamlWindowReference;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
private readonly App app;
|
||||
|
||||
public string Title
|
||||
@@ -40,8 +40,8 @@ internal sealed partial class NotifyIconViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
[Command("ShowMainWindowCommand")]
|
||||
private void ShowMainWindow()
|
||||
[Command("ShowWindowCommand")]
|
||||
private void ShowWindow()
|
||||
{
|
||||
switch (currentXamlWindowReference.Window)
|
||||
{
|
||||
@@ -61,22 +61,30 @@ internal sealed partial class NotifyIconViewModel : ObservableObject
|
||||
|
||||
// TODO: Can actually be no any window is initialized
|
||||
mainWindow.Show();
|
||||
mainWindow.WindowOptions.BringToForeground();
|
||||
break;
|
||||
}
|
||||
|
||||
case Window otherWindow:
|
||||
{
|
||||
if (otherWindow is IXamlWindowOptionsSource optionsSource)
|
||||
{
|
||||
otherWindow.Show();
|
||||
optionsSource.WindowOptions.BringToForeground();
|
||||
}
|
||||
|
||||
otherWindow.Show();
|
||||
(otherWindow as IXamlWindowOptionsSource)?.WindowOptions.BringToForeground();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command("LaunchGameCommand")]
|
||||
private async Task LaunchGame()
|
||||
{
|
||||
if (serviceProvider.GetRequiredService<IAppActivation>() is IAppActivationActionHandlersAccess access)
|
||||
{
|
||||
await access.HandleLaunchGameActionAsync();
|
||||
}
|
||||
|
||||
ShowWindow();
|
||||
}
|
||||
|
||||
[Command("ExitCommand")]
|
||||
private void Exit()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user