From 38e152befdbbe13556ab3e63b730248efd9a5d9f Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Mon, 13 May 2024 15:36:48 +0800 Subject: [PATCH] window reference logic --- .../Snap.Hutao/Core/LifeCycle/Activation.cs | 2 +- .../CurrentWindowReferenceExtension.cs | 24 ----------- ...rence.cs => CurrentXamlWindowReference.cs} | 8 ++-- .../CurrentXamlWindowReferenceExtension.cs | 23 ++++++++++ ...ence.cs => ICurrentXamlWindowReference.cs} | 4 +- .../NotifyIcon/NotifyIconContextMenu.xaml | 14 +++++-- .../NotifyIcon/NotifyIconController.cs | 4 +- .../NotifyIcon/NotifyIconMessageWindow.cs | 10 ----- .../NotifyIcon/NotifyIconXamlHostWindow.cs | 2 - .../Core/Windowing/WindowExtension.cs | 23 ++++++++++ .../Core/Windowing/XamlWindowController.cs | 23 +++++++--- .../ContentDialog/ContentDialogFactory.cs | 2 +- .../Picker/FileSystemPickerInteraction.cs | 2 +- src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs | 12 +++++- .../Snap.Hutao/Resource/Localization/SH.resx | 6 +++ .../ViewModel/NotifyIconViewModel.cs | 42 +++++++++++++++++++ .../Snap.Hutao/ViewModel/TestViewModel.cs | 13 +++--- .../Snap.Hutao/Web/Bridge/MiHoYoJSBridge.cs | 8 ++-- ...crect2Playload.cs => DataSignV2Payload.cs} | 2 +- 19 files changed, 156 insertions(+), 68 deletions(-) delete mode 100644 src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs rename src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/{CurrentWindowReference.cs => CurrentXamlWindowReference.cs} (64%) create mode 100644 src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReferenceExtension.cs rename src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/{ICurrentWindowReference.cs => ICurrentXamlWindowReference.cs} (72%) rename src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/{DynamicSecrect2Playload.cs => DataSignV2Payload.cs} (95%) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs index 32b20e11..1add1fe3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs @@ -38,7 +38,7 @@ internal sealed partial class Activation : IActivation, IDisposable private const string UrlActionRefresh = "/REFRESH"; private readonly IServiceProvider serviceProvider; - private readonly ICurrentWindowReference currentWindowReference; + private readonly ICurrentXamlWindowReference currentWindowReference; private readonly ITaskContext taskContext; private readonly SemaphoreSlim activateSemaphore = new(1); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs deleted file mode 100644 index ef5fc374..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.UI.Xaml; -using Snap.Hutao.Core.Windowing; -using Snap.Hutao.Win32.Foundation; -using WinRT.Interop; - -namespace Snap.Hutao.Core.LifeCycle; - -internal static class CurrentWindowReferenceExtension -{ - public static XamlRoot GetXamlRoot(this ICurrentWindowReference reference) - { - return reference.Window.Content.XamlRoot; - } - - public static HWND GetWindowHandle(this ICurrentWindowReference reference) - { - return reference.Window is IXamlWindowOptionsSource optionsSource - ? optionsSource.WindowOptions.Hwnd - : WindowNative.GetWindowHandle(reference.Window); - } -} diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReference.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReference.cs similarity index 64% rename from src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReference.cs rename to src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReference.cs index 6c880a8b..9650f054 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReference.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReference.cs @@ -5,19 +5,19 @@ using Microsoft.UI.Xaml; namespace Snap.Hutao.Core.LifeCycle; -[Injection(InjectAs.Singleton, typeof(ICurrentWindowReference))] -internal sealed class CurrentWindowReference : ICurrentWindowReference +[Injection(InjectAs.Singleton, typeof(ICurrentXamlWindowReference))] +internal sealed class CurrentXamlWindowReference : ICurrentXamlWindowReference { private readonly WeakReference reference = new(default!); [SuppressMessage("", "SH007")] - public Window Window + public Window? Window { get { reference.TryGetTarget(out Window? window); return window!; } - set => reference.SetTarget(value); + set => reference.SetTarget(value!); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReferenceExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReferenceExtension.cs new file mode 100644 index 00000000..e60939a4 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentXamlWindowReferenceExtension.cs @@ -0,0 +1,23 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.UI.Xaml; +using Snap.Hutao.Core.Windowing; +using Snap.Hutao.Win32.Foundation; +using WinRT.Interop; + +namespace Snap.Hutao.Core.LifeCycle; + +internal static class CurrentXamlWindowReferenceExtension +{ + public static XamlRoot GetXamlRoot(this ICurrentXamlWindowReference reference) + { + ArgumentNullException.ThrowIfNull(reference.Window); + return reference.Window.Content.XamlRoot; + } + + public static HWND GetWindowHandle(this ICurrentXamlWindowReference reference) + { + return WindowExtension.GetWindowHandle(reference.Window); + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentXamlWindowReference.cs similarity index 72% rename from src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs rename to src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentXamlWindowReference.cs index 2258c93b..de53769f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentXamlWindowReference.cs @@ -5,10 +5,10 @@ using Microsoft.UI.Xaml; namespace Snap.Hutao.Core.LifeCycle; -internal interface ICurrentWindowReference +internal interface ICurrentXamlWindowReference { /// /// Only set in WindowController /// - public Window Window { get; set; } + public Window? Window { get; set; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml index 064802d8..036c2751 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml @@ -32,13 +32,19 @@ - + + + Label="{shcm:ResourceString Name=CoreWindowingNotifyIconExitLabel}"/> diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs index 3834df9f..2315faf9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs @@ -1,7 +1,6 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Snap.Hutao.Core.ExceptionService; using Snap.Hutao.Win32.Foundation; @@ -40,9 +39,8 @@ internal sealed class NotifyIconController : IDisposable }, ContextMenuRequested = (window, point) => { - Flyout flyout = lazyMenu.Value; RECT iconRect = NotifyIconMethods.GetRect(Id, window.HWND); - xamlHostWindow.ShowFlyoutAt(flyout, new Windows.Foundation.Point(point.X, point.Y), iconRect); + xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), iconRect); }, }; diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs index d4f02e6d..889dbc8a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs @@ -1,16 +1,9 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Microsoft.UI; -using Microsoft.UI.Windowing; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; -using Snap.Hutao.Core.Windowing.Backdrop; using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.UI.WindowsAndMessaging; using System.Collections.Concurrent; -using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static Snap.Hutao.Win32.ConstValues; @@ -129,10 +122,8 @@ internal sealed class NotifyIconMessageWindow : IDisposable break; case WM_CONTEXTMENU: window.ContextMenuRequested?.Invoke(window, wParam2); - Debug.WriteLine($"[uMsg: 0x{uMsg:X8}] [X: {wParam2.X} Y: {wParam2.Y}] [Low: WM_CONTEXTMENU High: 0x{lParam2.High:X8}]"); break; default: - Debug.WriteLine($"[uMsg: 0x{uMsg:X8}] [X: {wParam2.X} Y: {wParam2.Y}] [Low: 0x{lParam2.Low:X8} High: 0x{lParam2.High:X8}]"); break; } } @@ -145,7 +136,6 @@ internal sealed class NotifyIconMessageWindow : IDisposable case WM_DWMNCRENDERINGCHANGED: break; default: - Debug.WriteLine($"[uMsg: 0x{uMsg:X8}] [wParam: 0x{wParam.Value:X8}] [lParam: 0x{lParam.Value:X8}]"); break; } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs index c22457e0..1535464d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs @@ -1,12 +1,10 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Media; using Snap.Hutao.Core.Windowing.Backdrop; using Snap.Hutao.Win32; using Snap.Hutao.Win32.Foundation; diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs index f70680b3..57a487c2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowExtension.cs @@ -22,6 +22,12 @@ internal static class WindowExtension WindowControllers.Add(window, windowController); } + public static bool IsControllerInitialized(this TWindow window) + where TWindow : Window + { + return WindowControllers.TryGetValue(window, out _); + } + public static void SetLayeredWindow(this Window window) { HWND hwnd = (HWND)WindowNative.GetWindowHandle(window); @@ -30,4 +36,21 @@ internal static class WindowExtension SetWindowLongPtrW(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, style); SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LAYERED_WINDOW_ATTRIBUTES_FLAGS.LWA_COLORKEY | LAYERED_WINDOW_ATTRIBUTES_FLAGS.LWA_ALPHA); } + + public static void Show(this Window window) + { + ShowWindow(GetWindowHandle(window), SHOW_WINDOW_CMD.SW_NORMAL); + } + + public static void Hide(this Window window) + { + ShowWindow(GetWindowHandle(window), SHOW_WINDOW_CMD.SW_HIDE); + } + + public static HWND GetWindowHandle(this Window? window) + { + return window is IXamlWindowOptionsSource optionsSource + ? optionsSource.WindowOptions.Hwnd + : WindowNative.GetWindowHandle(window); + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs index 5dcdd010..f103acab 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs @@ -36,8 +36,7 @@ internal sealed class XamlWindowController this.options = options; this.serviceProvider = serviceProvider; - // Window reference must be set before Window Subclass created - serviceProvider.GetRequiredService().Window = window; + serviceProvider.GetRequiredService().Window = window; subclass = new(window, options); windowNonRudeHWND = new(options.Hwnd); @@ -137,9 +136,23 @@ internal sealed class XamlWindowController private void OnWindowClosed(object sender, WindowEventArgs args) { - SaveOrSkipWindowSize(); - subclass?.Dispose(); - windowNonRudeHWND?.Dispose(); + if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true)) + { + args.Handled = true; + window.Hide(); + } + else + { + SaveOrSkipWindowSize(); + subclass?.Dispose(); + windowNonRudeHWND?.Dispose(); + + ICurrentXamlWindowReference currentXamlWindowReference = serviceProvider.GetRequiredService(); + if (currentXamlWindowReference.Window == window) + { + currentXamlWindowReference.Window = default!; + } + } } private void ExtendsContentIntoTitleBar() diff --git a/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialog/ContentDialogFactory.cs b/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialog/ContentDialogFactory.cs index 74598980..7c06a1b7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialog/ContentDialogFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialog/ContentDialogFactory.cs @@ -13,7 +13,7 @@ namespace Snap.Hutao.Factory.ContentDialog; [Injection(InjectAs.Singleton, typeof(IContentDialogFactory))] internal sealed partial class ContentDialogFactory : IContentDialogFactory { - private readonly ICurrentWindowReference currentWindowReference; + private readonly ICurrentXamlWindowReference currentWindowReference; private readonly IServiceProvider serviceProvider; private readonly ITaskContext taskContext; private readonly AppOptions appOptions; diff --git a/src/Snap.Hutao/Snap.Hutao/Factory/Picker/FileSystemPickerInteraction.cs b/src/Snap.Hutao/Snap.Hutao/Factory/Picker/FileSystemPickerInteraction.cs index 9642ff30..0b56d3b2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Factory/Picker/FileSystemPickerInteraction.cs +++ b/src/Snap.Hutao/Snap.Hutao/Factory/Picker/FileSystemPickerInteraction.cs @@ -18,7 +18,7 @@ namespace Snap.Hutao.Factory.Picker; [Injection(InjectAs.Transient, typeof(IFileSystemPickerInteraction))] internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInteraction { - private readonly ICurrentWindowReference currentWindowReference; + private readonly ICurrentXamlWindowReference currentWindowReference; public unsafe ValueResult PickFile(string? title, string? defaultFileName, (string Name, string Type)[]? filters) { diff --git a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs index c0b0ccef..c907bac1 100644 --- a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs @@ -13,7 +13,6 @@ namespace Snap.Hutao; /// [HighQuality] [Injection(InjectAs.Singleton)] -[SuppressMessage("", "CA1001")] internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMinMaxInfoHandler { private const int MinWidth = 1000; @@ -30,6 +29,8 @@ internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMi InitializeComponent(); windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), SettingKeys.WindowRect); this.InitializeController(serviceProvider); + + Closed += OnClosed; } /// @@ -41,4 +42,13 @@ internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMi pInfo.ptMinTrackSize.x = (int)Math.Max(MinWidth * scalingFactor, pInfo.ptMinTrackSize.x); pInfo.ptMinTrackSize.y = (int)Math.Max(MinHeight * scalingFactor, pInfo.ptMinTrackSize.y); } + + private void OnClosed(object sender, WindowEventArgs args) + { + if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true)) + { + args.Handled = true; + this.Hide(); + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 73dee2ef..824f7042 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -192,6 +192,12 @@ [{0}] 热键 [{1}] 注册失败 + + 退出 + + + 主界面 + 深色 diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/NotifyIconViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/NotifyIconViewModel.cs index 265658f7..83c3997d 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/NotifyIconViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/NotifyIconViewModel.cs @@ -2,7 +2,10 @@ // Licensed under the MIT license. using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.UI.Xaml; using Snap.Hutao.Core; +using Snap.Hutao.Core.LifeCycle; +using Snap.Hutao.Core.Windowing; using System.Globalization; using System.Text; @@ -13,6 +16,8 @@ namespace Snap.Hutao.ViewModel; internal sealed partial class NotifyIconViewModel : ObservableObject { private readonly RuntimeOptions runtimeOptions; + private readonly ICurrentXamlWindowReference currentXamlWindowReference; + private readonly IServiceProvider serviceProvider; private readonly App app; public string Title @@ -35,6 +40,43 @@ internal sealed partial class NotifyIconViewModel : ObservableObject } } + [Command("ShowMainWindowCommand")] + private void ShowMainWindow() + { + switch (currentXamlWindowReference.Window) + { + case MainWindow mainWindow: + { + // MainWindow is activated, bring to foreground + mainWindow.Show(); + mainWindow.WindowOptions.BringToForeground(); + return; + } + + case null: + { + // MainWindow is hided, show it + MainWindow mainWindow = serviceProvider.GetRequiredService(); + currentXamlWindowReference.Window = mainWindow; + + // TODO: Can actually be no any window is initialized + mainWindow.Show(); + break; + } + + case Window otherWindow: + { + if (otherWindow is IXamlWindowOptionsSource optionsSource) + { + otherWindow.Show(); + optionsSource.WindowOptions.BringToForeground(); + } + + return; + } + } + } + [Command("ExitCommand")] private void Exit() { diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/TestViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/TestViewModel.cs index 95ed2f77..18fd0e1a 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/TestViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/TestViewModel.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Caching.Memory; using Snap.Hutao.Core; using Snap.Hutao.Core.Caching; +using Snap.Hutao.Core.ExceptionService; using Snap.Hutao.Core.LifeCycle; using Snap.Hutao.Core.Setting; using Snap.Hutao.Service.Notification; @@ -46,7 +47,6 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel private readonly ILogger logger; private readonly IMemoryCache memoryCache; private readonly ITaskContext taskContext; - private readonly MainWindow mainWindow; private UploadAnnouncement announcement = new(); @@ -117,14 +117,17 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel [Command("ExceptionCommand")] private static void ThrowTestException() { - Must.NeverHappen(); + HutaoException.Throw("Test Exception"); } [Command("ResetMainWindowSizeCommand")] private void ResetMainWindowSize() { - double scale = mainWindow.WindowOptions.GetRasterizationScale(); - mainWindow.AppWindow.Resize(new Windows.Graphics.SizeInt32(1372, 772).Scale(scale)); + if (serviceProvider.GetRequiredService().Window is MainWindow mainWindow) + { + double scale = mainWindow.WindowOptions.GetRasterizationScale(); + mainWindow.AppWindow.Resize(new Windows.Graphics.SizeInt32(1372, 772).Scale(scale)); + } } [Command("UploadAnnouncementCommand")] @@ -186,7 +189,7 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel { IDirect3DDevice direct3DDevice = WinRT.IInspectable.FromAbi((nint)inspectable).ObjRef.AsInterface(); - HWND hwnd = serviceProvider.GetRequiredService().GetWindowHandle(); + HWND hwnd = serviceProvider.GetRequiredService().GetWindowHandle(); GraphicsCaptureItem.As().CreateForWindow(hwnd, out GraphicsCaptureItem item); using (Direct3D11CaptureFramePool framePool = Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size)) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSBridge.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSBridge.cs index 43b1a422..cb5673a8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSBridge.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSBridge.cs @@ -195,7 +195,7 @@ internal class MiHoYoJSBridge }; } - protected virtual JsResult> GetDynamicSecrectV1(JsParam param) + protected virtual JsResult> GetDataSignV1(JsParam param) { DataSignOptions options = DataSignOptions.CreateForGeneration1(SaltType.LK2, true); return new() @@ -207,7 +207,7 @@ internal class MiHoYoJSBridge }; } - protected virtual JsResult> GetDynamicSecrectV2(JsParam param) + protected virtual JsResult> GetDataSignV2(JsParam param) { DataSignOptions options = DataSignOptions.CreateForGeneration2(SaltType.X4, false, param.Payload.Body, param.Payload.GetQueryParam()); return new() @@ -451,8 +451,8 @@ internal class MiHoYoJSBridge "getCookieInfo" => GetCookieInfo(param), "getCookieToken" => await GetCookieTokenAsync(param).ConfigureAwait(false), "getCurrentLocale" => GetCurrentLocale(param), - "getDS" => GetDynamicSecrectV1(param), - "getDS2" => GetDynamicSecrectV2(param), + "getDS" => GetDataSignV1(param), + "getDS2" => GetDataSignV2(param), "getHTTPRequestHeaders" => GetHttpRequestHeader(param), "getStatusBarHeight" => GetStatusBarHeight(param), "getUserInfo" => await GetUserInfoAsync(param).ConfigureAwait(false), diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/DynamicSecrect2Playload.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/DataSignV2Payload.cs similarity index 95% rename from src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/DynamicSecrect2Playload.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/DataSignV2Payload.cs index 0cb8669b..376f0374 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/DynamicSecrect2Playload.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/DataSignV2Payload.cs @@ -7,7 +7,7 @@ namespace Snap.Hutao.Web.Bridge.Model; /// DS2请求 /// [HighQuality] -internal sealed class DynamicSecrect2Playload +internal sealed class DataSignV2Payload { /// /// q