diff --git a/src/Snap.Hutao/Snap.Hutao/App.xaml b/src/Snap.Hutao/Snap.Hutao/App.xaml index 2f382bce..e2ad5be8 100644 --- a/src/Snap.Hutao/Snap.Hutao/App.xaml +++ b/src/Snap.Hutao/Snap.Hutao/App.xaml @@ -1,275 +1,30 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - #FF74BF00 - #FFF4F4F4 - - - - #FF90E800 - #FF242424 - - - - - - 4,4,0,0 - 0,0,4,4 - 6 - 6,6,0,0 - 0,6,6,0 - 0,0,6,6 - 2 - - 288 - 212 - 304 - 320 - 180 - 64 - 100 - - 0.2 - - - - - - - - - - https://hut.ao/features/mhy-account-switch.html - https://hut.ao/statements/bug-report.html - https://translate.hut.ao - https://hut.ao - https://github.com/HolographicHat/GetToken/releases/latest - https://afdian.net/a/DismissedLight - - - https://static.snapgenshin.com/Bg/UI_ItemIcon_None.png - https://static.snapgenshin.com/Bg/UI_MarkTower.png - https://static.snapgenshin.com/Bg/UI_Icon_Intee_Explore_1.png - https://static.snapgenshin.com/Bg/UI_MarkQuest_Events_Proce.png - https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_201.png - https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_204.png - https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_210.png - https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_220021.png - https://static.snapgenshin.com/Bg/UI_ImgSign_ItemIcon.png - https://static.snapgenshin.com/AvatarCard/UI_AvatarIcon_Costume_Card.png - https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon25.png - https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon71.png - https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon250.png - https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon272.png - https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon293.png - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Image/CachedImage.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Image/CachedImage.xaml new file mode 100644 index 00000000..e64ab600 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Image/CachedImage.xaml @@ -0,0 +1,82 @@ + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Image/CompositionImage.cs b/src/Snap.Hutao/Snap.Hutao/Control/Image/CompositionImage.cs index 73edd26f..da2127fa 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Image/CompositionImage.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Image/CompositionImage.cs @@ -164,11 +164,26 @@ internal abstract partial class CompositionImage : Microsoft.UI.Xaml.Controls.Co private async ValueTask LoadImageSurfaceAsync(string file, CancellationToken token) { surfaceLoadTaskCompletionSource = new(); - LoadedImageSurface surface = LoadedImageSurface.StartLoadFromUri(file.ToUri()); - surface.LoadCompleted += loadedImageSourceLoadCompletedEventHandler; - await surfaceLoadTaskCompletionSource.Task.ConfigureAwait(true); - LoadImageSurfaceCompleted(surface); - return surface; + LoadedImageSurface? surface = default; + try + { + surface = LoadedImageSurface.StartLoadFromUri(file.ToUri()); + surface.LoadCompleted += loadedImageSourceLoadCompletedEventHandler; + if (surface.NaturalSize.Size() <= 0D) + { + await surfaceLoadTaskCompletionSource.Task.ConfigureAwait(true); + } + + LoadImageSurfaceCompleted(surface); + return surface; + } + finally + { + if (surface is not null) + { + surface.LoadCompleted -= loadedImageSourceLoadCompletedEventHandler; + } + } } private async ValueTask ShowAsync(CancellationToken token) @@ -216,7 +231,6 @@ internal abstract partial class CompositionImage : Microsoft.UI.Xaml.Controls.Co private void OnLoadImageSurfaceLoadCompleted(LoadedImageSurface surface, LoadedImageSourceLoadCompletedEventArgs e) { surfaceLoadTaskCompletionSource?.TrySetResult(); - surface.LoadCompleted -= loadedImageSourceLoadCompletedEventHandler; } private void OnSizeChanged(object sender, SizeChangedEventArgs e) diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/Card.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Card.xaml new file mode 100644 index 00000000..d42eb68e --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Card.xaml @@ -0,0 +1,21 @@ + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/Color.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Color.xaml new file mode 100644 index 00000000..8557c744 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Color.xaml @@ -0,0 +1,31 @@ + + + + #FF74BF00 + #FFF4F4F4 + #00000000 + + + #FF90E800 + #FF242424 + #60000000 + + + + #FF5180CB + #FFA156E0 + #FFBC6932 + + #FF0063FF + #FFFFA400 + + + + + + + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/Converter.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Converter.xaml new file mode 100644 index 00000000..beef99ac --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Converter.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/CornerRadius.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/CornerRadius.xaml new file mode 100644 index 00000000..f2ebb9f5 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/CornerRadius.xaml @@ -0,0 +1,4 @@ + + 4,4,0,0 + 0,0,4,4 + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/FontStyle.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/FontStyle.xaml index 18fd7359..3d7f052c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Theme/FontStyle.xaml +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/FontStyle.xaml @@ -1,7 +1,4 @@ - + ms-appx:///Resource/Font/MiSans-Regular.ttf#MiSans ms-appx:///Resource/Font/CascadiaMono.ttf#Cascadia Mono, ms-appx:///Resource/Font/MiSans-Regular.ttf#MiSans diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/Glyph.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Glyph.xaml new file mode 100644 index 00000000..8e5db5ad --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Glyph.xaml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/ItemContainerStyle.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/ItemContainerStyle.xaml new file mode 100644 index 00000000..d2a12ec4 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/ItemContainerStyle.xaml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/ItemsPanelTemplate.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/ItemsPanelTemplate.xaml new file mode 100644 index 00000000..46d10041 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/ItemsPanelTemplate.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/NumericValue.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/NumericValue.xaml new file mode 100644 index 00000000..89cef2a7 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/NumericValue.xaml @@ -0,0 +1,14 @@ + + + 288 + + 212 + 304 + 320 + 180 + 64 + 100 + + + 0.2 + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/PageOverride.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/PageOverride.xaml index 50327554..fadb4b6a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Theme/PageOverride.xaml +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/PageOverride.xaml @@ -2,5 +2,5 @@ - 0 + 0 \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/SettingsStyle.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/SettingsStyle.xaml index 144c250c..f0182d63 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Theme/SettingsStyle.xaml +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/SettingsStyle.xaml @@ -18,4 +18,14 @@ TargetType="ComboBox"> + diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/Uri.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Uri.xaml new file mode 100644 index 00000000..3e50461f --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/Uri.xaml @@ -0,0 +1,34 @@ + + + https://hut.ao/statements/bug-report.html + https://hut.ao + https://hut.ao/features/mhy-account-switch.html + https://translate.hut.ao + + + https://github.com/HolographicHat/GetToken/releases/latest + https://afdian.net/a/DismissedLight + + + https://static.snapgenshin.com/AvatarCard/UI_AvatarIcon_Costume_Card.png + + + https://static.snapgenshin.com/Bg/UI_Icon_Intee_Explore_1.png + https://static.snapgenshin.com/Bg/UI_ImgSign_ItemIcon.png + https://static.snapgenshin.com/Bg/UI_ItemIcon_None.png + https://static.snapgenshin.com/Bg/UI_MarkQuest_Events_Proce.png + https://static.snapgenshin.com/Bg/UI_MarkTower.png + + + https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_201.png + https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_204.png + https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_210.png + https://static.snapgenshin.com/ItemIcon/UI_ItemIcon_220021.png + + + https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon25.png + https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon71.png + https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon250.png + https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon272.png + https://static.snapgenshin.com/EmotionIcon/UI_EmotionIcon293.png + diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ExceptionRecorder.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ExceptionRecorder.cs index 979b767b..358f83b8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ExceptionRecorder.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ExceptionRecorder.cs @@ -14,9 +14,7 @@ namespace Snap.Hutao.Core.ExceptionService; internal sealed partial class ExceptionRecorder { private readonly ILogger logger; -#if RELEASE private readonly IServiceProvider serviceProvider; -#endif /// /// 记录应用程序异常 @@ -31,13 +29,11 @@ internal sealed partial class ExceptionRecorder private void OnAppUnhandledException(object? sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) { -#if RELEASE serviceProvider .GetRequiredService() .UploadLogAsync(e.Exception) .GetAwaiter() .GetResult(); -#endif logger.LogError("未经处理的全局异常:\r\n{Detail}", ExceptionFormat.Format(e.Exception)); } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyController.cs index 30da56c5..a2b4c497 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyController.cs @@ -48,7 +48,7 @@ internal sealed class HotKeyController : IHotKeyController public void OnHotKeyPressed(in HotKeyParameter parameter) { - if (parameter is { Key: VIRTUAL_KEY.VK_F8, Modifier: 0 }) + if (parameter is { Key: VIRTUAL_KEY.VK_F8, NativeModifier: 0 }) { lock (locker) { diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyParameter.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyParameter.cs index 4cc9b88e..8a8cf3e2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyParameter.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyParameter.cs @@ -7,6 +7,11 @@ namespace Snap.Hutao.Core.Windowing.HotKey; internal readonly struct HotKeyParameter { - public readonly ushort Modifier; + public readonly ushort NativeModifier; public readonly VIRTUAL_KEY Key; + + public readonly HOT_KEY_MODIFIERS Modifier + { + get => (HOT_KEY_MODIFIERS)NativeModifier; + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IMinMaxInfoHandler.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IMinMaxInfoHandler.cs new file mode 100644 index 00000000..eee91675 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IMinMaxInfoHandler.cs @@ -0,0 +1,16 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Windows.Win32.UI.WindowsAndMessaging; + +namespace Snap.Hutao.Core.Windowing; + +internal interface IMinMaxInfoHandler +{ + /// + /// 处理最大最小信息 + /// + /// 信息 + /// 缩放比 + unsafe void HandleMinMaxInfo(ref MINMAXINFO info, double scalingFactor); +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IWindowOptionsSource.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IWindowOptionsSource.cs index 8861026c..5c878657 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IWindowOptionsSource.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/IWindowOptionsSource.cs @@ -1,8 +1,6 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Windows.Win32.UI.WindowsAndMessaging; - namespace Snap.Hutao.Core.Windowing; /// @@ -14,11 +12,4 @@ internal interface IWindowOptionsSource /// 窗体选项 /// WindowOptions WindowOptions { get; } - - /// - /// 处理最大最小信息 - /// - /// 信息指针 - /// 缩放比 - unsafe void ProcessMinMaxInfo(MINMAXINFO* pInfo, double scalingFactor); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs index af847d74..946fc5bc 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs @@ -76,15 +76,15 @@ internal sealed class WindowController { // Set first launch size double scale = options.GetWindowScale(); - SizeInt32 transformedSize = options.InitSize.Scale(scale); - RectInt32 rect = StructMarshal.RectInt32(transformedSize); + SizeInt32 scaledSize = options.InitSize.Scale(scale); + RectInt32 rect = StructMarshal.RectInt32(scaledSize); if (options.PersistSize) { RectInt32 persistedRect = (CompactRect)LocalSetting.Get(SettingKeys.WindowRect, (CompactRect)rect); if (persistedRect.Size() >= options.InitSize.Size()) { - rect = persistedRect; + rect = persistedRect.Scale(scale); } } @@ -105,7 +105,8 @@ internal sealed class WindowController // prevent save value when we are maximized. if (!windowPlacement.showCmd.HasFlag(SHOW_WINDOW_CMD.SW_SHOWMAXIMIZED)) { - LocalSetting.Set(SettingKeys.WindowRect, (CompactRect)window.AppWindow.GetRect()); + double scale = 1 / options.GetWindowScale(); + LocalSetting.Set(SettingKeys.WindowRect, (CompactRect)window.AppWindow.GetRect().Scale(scale)); } } @@ -113,8 +114,10 @@ internal sealed class WindowController { if (e.PropertyName == nameof(AppOptions.BackdropType)) { - ArgumentNullException.ThrowIfNull(sender); - UpdateSystemBackdrop(((AppOptions)sender).BackdropType); + if (sender is AppOptions options) + { + UpdateSystemBackdrop(options.BackdropType); + } } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclass.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclass.cs index 640c0a6f..14cc9297 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclass.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclass.cs @@ -71,17 +71,16 @@ internal sealed class WindowSubclass : IDisposable /// public void Dispose() { + hotKeyController.Unregister(options.Hwnd); + RemoveWindowSubclass(options.Hwnd, windowProc, WindowSubclassId); windowProc = null; - if (!options.UseLegacyDragBarImplementation) + if (options.UseLegacyDragBarImplementation) { - return; + RemoveWindowSubclass(options.Hwnd, legacyDragBarProc, DragBarSubclassId); + legacyDragBarProc = null; } - - hotKeyController.Unregister(options.Hwnd); - RemoveWindowSubclass(options.Hwnd, legacyDragBarProc, DragBarSubclassId); - legacyDragBarProc = null; } [SuppressMessage("", "SH002")] @@ -91,16 +90,18 @@ internal sealed class WindowSubclass : IDisposable { case WM_GETMINMAXINFO: { - uint dpi = GetDpiForWindow(hwnd); - double scalingFactor = Math.Round(dpi / 96D, 2, MidpointRounding.AwayFromZero); - ((IWindowOptionsSource)window).ProcessMinMaxInfo((MINMAXINFO*)lParam.Value, scalingFactor); + if (window is IMinMaxInfoHandler handler) + { + handler.HandleMinMaxInfo(ref *(MINMAXINFO*)lParam.Value, options.GetWindowScale()); + } + break; } case WM_NCRBUTTONDOWN: case WM_NCRBUTTONUP: { - return (LRESULT)(nint)WM_NULL; + return default; } case WM_HOTKEY: diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/StructExtension.cs b/src/Snap.Hutao/Snap.Hutao/Extension/StructExtension.cs index bb009b57..c8b7f949 100644 --- a/src/Snap.Hutao/Snap.Hutao/Extension/StructExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Extension/StructExtension.cs @@ -62,4 +62,9 @@ internal static class StructExtension { return sizeInt32.Width * sizeInt32.Height; } + + public static double Size(this Windows.Foundation.Size size) + { + return size.Width * size.Height; + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/GuideWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/GuideWindow.xaml.cs index f477a883..82122e58 100644 --- a/src/Snap.Hutao/Snap.Hutao/GuideWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/GuideWindow.xaml.cs @@ -11,7 +11,7 @@ namespace Snap.Hutao; /// 指引窗口 /// [Injection(InjectAs.Singleton)] -internal sealed partial class GuideWindow : Window, IWindowOptionsSource +internal sealed partial class GuideWindow : Window, IWindowOptionsSource, IMinMaxInfoHandler { private const int MinWidth = 1000; private const int MinHeight = 600; @@ -30,11 +30,11 @@ internal sealed partial class GuideWindow : Window, IWindowOptionsSource WindowOptions IWindowOptionsSource.WindowOptions { get => windowOptions; } - public unsafe void ProcessMinMaxInfo(MINMAXINFO* pInfo, double scalingFactor) + public unsafe void HandleMinMaxInfo(ref MINMAXINFO info, double scalingFactor) { - pInfo->ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, pInfo->ptMinTrackSize.X); - pInfo->ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, pInfo->ptMinTrackSize.Y); - pInfo->ptMaxTrackSize.X = (int)Math.Min(MaxWidth * scalingFactor, pInfo->ptMaxTrackSize.X); - pInfo->ptMaxTrackSize.Y = (int)Math.Min(MaxHeight * scalingFactor, pInfo->ptMaxTrackSize.Y); + info.ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, info.ptMinTrackSize.X); + info.ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, info.ptMinTrackSize.Y); + info.ptMaxTrackSize.X = (int)Math.Min(MaxWidth * scalingFactor, info.ptMaxTrackSize.X); + info.ptMaxTrackSize.Y = (int)Math.Min(MaxHeight * scalingFactor, info.ptMaxTrackSize.Y); } } diff --git a/src/Snap.Hutao/Snap.Hutao/LaunchGameWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/LaunchGameWindow.xaml.cs index cba90226..43d75331 100644 --- a/src/Snap.Hutao/Snap.Hutao/LaunchGameWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/LaunchGameWindow.xaml.cs @@ -13,7 +13,7 @@ namespace Snap.Hutao; /// [HighQuality] [Injection(InjectAs.Singleton)] -internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOptionsSource +internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOptionsSource, IMinMaxInfoHandler { private const int MinWidth = 240; private const int MinHeight = 240; @@ -48,11 +48,11 @@ internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOpt } /// - public unsafe void ProcessMinMaxInfo(MINMAXINFO* pInfo, double scalingFactor) + public unsafe void HandleMinMaxInfo(ref MINMAXINFO info, double scalingFactor) { - pInfo->ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, pInfo->ptMinTrackSize.X); - pInfo->ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, pInfo->ptMinTrackSize.Y); - pInfo->ptMaxTrackSize.X = (int)Math.Min(MaxWidth * scalingFactor, pInfo->ptMaxTrackSize.X); - pInfo->ptMaxTrackSize.Y = (int)Math.Min(MaxHeight * scalingFactor, pInfo->ptMaxTrackSize.Y); + info.ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, info.ptMinTrackSize.X); + info.ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, info.ptMinTrackSize.Y); + info.ptMaxTrackSize.X = (int)Math.Min(MaxWidth * scalingFactor, info.ptMaxTrackSize.X); + info.ptMaxTrackSize.Y = (int)Math.Min(MaxHeight * scalingFactor, info.ptMaxTrackSize.Y); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs index e49d951d..52532905 100644 --- a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs @@ -14,7 +14,7 @@ namespace Snap.Hutao; [HighQuality] [Injection(InjectAs.Singleton)] [SuppressMessage("", "CA1001")] -internal sealed partial class MainWindow : Window, IWindowOptionsSource +internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMaxInfoHandler { private const int MinWidth = 848; private const int MinHeight = 524; @@ -46,10 +46,10 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource public WindowOptions WindowOptions { get => windowOptions; } /// - public unsafe void ProcessMinMaxInfo(MINMAXINFO* pInfo, double scalingFactor) + public unsafe void HandleMinMaxInfo(ref MINMAXINFO pInfo, double scalingFactor) { - pInfo->ptMinTrackSize.X = (int)Math.Max(MinWidth * scalingFactor, pInfo->ptMinTrackSize.X); - pInfo->ptMinTrackSize.Y = (int)Math.Max(MinHeight * scalingFactor, pInfo->ptMinTrackSize.Y); + 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) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs index e7a0ed68..b7d3178b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs @@ -235,7 +235,7 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker using (localMemory) { - int offset = IndexOfPattern(localMemory.Span[(int)moduleEntryInfo.UnityPlayer.Size..]); + int offset = IndexOfPattern(localMemory.AsSpan()[(int)moduleEntryInfo.UnityPlayer.Size..]); Must.Range(offset >= 0, SH.ServiceGameUnlockerInterestedPatternNotFound); byte* pLocalMemory = (byte*)localMemory.Pointer; diff --git a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj index 67d6b18a..93573a54 100644 --- a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj +++ b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj @@ -72,14 +72,24 @@ + + + + + + + + + + @@ -239,12 +249,12 @@ - - - - - - + + + + + + @@ -253,8 +263,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -262,7 +272,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -303,6 +313,66 @@ + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + MSBuild:Compile diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml index b77f3fc6..be224ffb 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml @@ -66,16 +66,16 @@ Description="{Binding LastOrangePull}" Header="{shcm:ResourceString Name=ViewControlStatisticsCardOrangeText}" Maximum="{Binding GuaranteeOrangeThreshold}" - ProgressForeground="{StaticResource OrangeBrush}" - TextForeground="{StaticResource OrangeBrush}" + ProgressForeground="{StaticResource OrangeColorBrush}" + TextForeground="{StaticResource OrangeColorBrush}" Value="{Binding LastOrangePull}"/> @@ -98,16 +98,16 @@ Description="{Binding LastOrangePull}" Header="{shcm:ResourceString Name=ViewControlStatisticsCardOrangeText}" Maximum="{Binding GuaranteeOrangeThreshold}" - ProgressForeground="{StaticResource OrangeBrush}" - TextForeground="{StaticResource OrangeBrush}" + ProgressForeground="{StaticResource OrangeColorBrush}" + TextForeground="{StaticResource OrangeColorBrush}" Value="{Binding LastOrangePull}"/> @@ -129,16 +129,16 @@ Description="{Binding LastOrangePull}" Header="{shcm:ResourceString Name=ViewControlStatisticsCardOrangeText}" Maximum="{Binding GuaranteeOrangeThreshold}" - ProgressForeground="{StaticResource OrangeBrush}" - TextForeground="{StaticResource OrangeBrush}" + ProgressForeground="{StaticResource OrangeColorBrush}" + TextForeground="{StaticResource OrangeColorBrush}" Value="{Binding LastOrangePull}"/> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardBlock.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardBlock.xaml index 33faaff1..7d7dccaa 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardBlock.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardBlock.xaml @@ -6,7 +6,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shci="using:Snap.Hutao.Control.Image" - Style="{StaticResource BorderGridStyle}" + Style="{ThemeResource GridCardStyle}" mc:Ignorable="d"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardProgressBar.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardProgressBar.xaml index d3fb37cf..8c622def 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardProgressBar.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/Primitive/CardProgressBar.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinHeight="40" - Style="{StaticResource BorderGridStyle}" + Style="{ThemeResource GridCardStyle}" mc:Ignorable="d"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml index 75365135..028c986f 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml @@ -26,7 +26,7 @@ - + @@ -36,7 +36,7 @@ Grid.Row="0" cw:UIElementExtensions.ClipToBounds="True" CornerRadius="{StaticResource ControlCornerRadiusTop}" - Style="{StaticResource BorderGridStyle}"> + Style="{ThemeResource GridCardStyle}"> - + @@ -59,13 +59,13 @@ @@ -103,7 +103,7 @@ - + @@ -181,8 +181,8 @@ Description="{Binding LastOrangePull}" Header="{shcm:ResourceString Name=ViewControlStatisticsCardToLastOrangeText}" Maximum="{Binding GuaranteeOrangeThreshold}" - ProgressForeground="{StaticResource OrangeBrush}" - TextForeground="{StaticResource OrangeBrush}" + ProgressForeground="{StaticResource OrangeColorBrush}" + TextForeground="{StaticResource OrangeColorBrush}" Value="{Binding LastOrangePull}"/> @@ -243,37 +243,37 @@ diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs index 480e2a44..e9326fa2 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs @@ -2,8 +2,10 @@ // Licensed under the MIT license. using CommunityToolkit.Mvvm.Messaging; +using Microsoft.UI.Content; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Hosting; using Microsoft.Web.WebView2.Core; using Snap.Hutao.Message; using Snap.Hutao.Service.Notification; @@ -20,7 +22,6 @@ internal partial class WebViewer : UserControl, IRecipient private readonly RoutedEventHandler loadEventHandler; private readonly RoutedEventHandler unloadEventHandler; - [SuppressMessage("", "IDE0052")] private MiHoYoJSInterface? jsInterface; public WebViewer() @@ -49,7 +50,6 @@ internal partial class WebViewer : UserControl, IRecipient private void OnUnloaded(object sender, RoutedEventArgs e) { - jsInterface = null; Loaded -= loadEventHandler; Unloaded -= unloadEventHandler; } @@ -86,13 +86,16 @@ internal partial class WebViewer : UserControl, IRecipient string source = SourceProvider.GetSource(userAndUid); if (!string.IsNullOrEmpty(source)) { - await coreWebView2.DeleteCookiesAsync(".mihoyo.com").ConfigureAwait(true); - coreWebView2.SetCookie(user.CookieToken, user.LToken, user.SToken); - _ = userAndUid.User.IsOversea ? coreWebView2.SetMobileOverseaUserAgent() : coreWebView2.SetMobileUserAgent(); - jsInterface = SourceProvider.CreateJsInterface(serviceProvider, coreWebView2, userAndUid); + await coreWebView2.Profile.ClearBrowsingDataAsync(); CoreWebView2Navigator navigator = new(coreWebView2); await navigator.NavigateAsync("about:blank").ConfigureAwait(true); + + coreWebView2.SetCookie(user.CookieToken, user.LToken, user.SToken); + _ = userAndUid.User.IsOversea ? coreWebView2.SetMobileOverseaUserAgent() : coreWebView2.SetMobileUserAgent(); + jsInterface?.Detach(); + jsInterface = SourceProvider.CreateJsInterface(serviceProvider, coreWebView2, userAndUid); + await navigator.NavigateAsync(source).ConfigureAwait(true); } } diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/CultivatePromotionDeltaDialog.xaml b/src/Snap.Hutao/Snap.Hutao/View/Dialog/CultivatePromotionDeltaDialog.xaml index 7d0de834..71055f38 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/CultivatePromotionDeltaDialog.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/CultivatePromotionDeltaDialog.xaml @@ -76,7 +76,7 @@ + Style="{ThemeResource GridCardStyle}"> @@ -129,7 +129,7 @@ + Style="{ThemeResource GridCardStyle}"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/AvatarPropertyPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/AvatarPropertyPage.xaml index 35679ff6..8aef9263 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/AvatarPropertyPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/AvatarPropertyPage.xaml @@ -314,7 +314,7 @@ HorizontalAlignment="Left"> - + @@ -636,7 +636,7 @@ Grid.Column="3" Margin="8,0,0,0" HorizontalAlignment="Left" - Foreground="{StaticResource AvatarPropertyAddValueBrush}" + Foreground="{StaticResource AvatarPropertyAddValueColorBrush}" Text="{Binding AddValue}"/> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/DailyNotePage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/DailyNotePage.xaml index cef97178..3ea16f55 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/DailyNotePage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/DailyNotePage.xaml @@ -193,7 +193,7 @@ - + @@ -284,7 +284,7 @@ Grid.Row="1" Margin="0,8,0,0" Spacing="6"> - + @@ -321,7 +321,7 @@ TextWrapping="NoWrap"/> - + @@ -358,7 +358,7 @@ TextWrapping="NoWrap"/> - + @@ -395,7 +395,7 @@ TextWrapping="NoWrap"/> - + @@ -432,7 +432,7 @@ TextWrapping="NoWrap"/> - + @@ -487,7 +487,7 @@ - + diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/ISupportLoginByWebView.cs b/src/Snap.Hutao/Snap.Hutao/View/Page/ISupportLoginByWebView.cs index 357aa8a8..34046301 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/ISupportLoginByWebView.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/ISupportLoginByWebView.cs @@ -17,11 +17,11 @@ internal interface ISupportLoginByWebView try { await webView2.EnsureCoreWebView2Async(); - await webView2.CoreWebView2.DeleteCookiesAsync("https://user.mihoyo.com").ConfigureAwait(true); + await webView2.CoreWebView2.DeleteCookiesAsync(cookie).ConfigureAwait(true); webView2.CoreWebView2.DisableDevToolsOnReleaseBuild(); webView2.CoreWebView2.DisableAutoCompletion(); - webView2.CoreWebView2.Navigate("https://user.mihoyo.com/#/login/password"); + webView2.CoreWebView2.Navigate(navigate); } catch (Exception ex) { diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/LoginMihoyoUserPage.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Page/LoginMihoyoUserPage.xaml.cs index 1863556e..c32a41d0 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/LoginMihoyoUserPage.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/LoginMihoyoUserPage.xaml.cs @@ -44,7 +44,7 @@ internal sealed partial class LoginMihoyoUserPage : Microsoft.UI.Xaml.Controls.P IReadOnlyList cookies = await WebView.CoreWebView2.CookieManager.GetCookiesAsync("https://user.mihoyo.com"); Cookie webCookie = Cookie.FromCoreWebView2Cookies(cookies); - if (!webCookie.TryGetCookieToken(out Cookie? loginTicketCookie)) + if (!webCookie.TryGetLoginTicket(out Cookie? loginTicketCookie)) { return; } diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml index 7270a3d5..23a69bd9 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml @@ -21,7 +21,7 @@ - + + + +