diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Behavior/InvokeCommandOnUnloadedBehavior.cs b/src/Snap.Hutao/Snap.Hutao/Control/Behavior/InvokeCommandOnUnloadedBehavior.cs index cb218fae31..7976e75b8e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Behavior/InvokeCommandOnUnloadedBehavior.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Behavior/InvokeCommandOnUnloadedBehavior.cs @@ -32,4 +32,4 @@ protected override void OnDetaching() base.OnDetaching(); } -} \ No newline at end of file +} diff --git a/src/Snap.Hutao/Snap.Hutao/Core/CoreEnvironment.cs b/src/Snap.Hutao/Snap.Hutao/Core/CoreEnvironment.cs index de168e725f..3e1d6e213a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/CoreEnvironment.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/CoreEnvironment.cs @@ -20,6 +20,11 @@ internal static class CoreEnvironment /// public const string HoyolabUA = $"Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/{HoyolabXrpcVersion}"; + /// + /// 米游社移动端请求UA + /// + public const string HoyolabMobileUA = $"Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/106.0.5249.126 Mobile Safari/537.36 miHoYoBBS/{HoyolabXrpcVersion}"; + /// /// 米游社 Rpc 版本 /// diff --git a/src/Snap.Hutao/Snap.Hutao/Core/TaskSchedulerHelper.cs b/src/Snap.Hutao/Snap.Hutao/Core/TaskSchedulerHelper.cs index 004c5c485b..254468f59b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/TaskSchedulerHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/TaskSchedulerHelper.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using Microsoft.Win32.TaskScheduler; +using System.Runtime.InteropServices; using SchedulerTask = Microsoft.Win32.TaskScheduler.Task; namespace Snap.Hutao.Core; @@ -39,5 +40,9 @@ public static bool RegisterForDailyNoteRefresh(int interval) { return false; } + catch (COMException) + { + return false; + } } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs b/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs index 1f0420ad11..429cabcfa6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs @@ -38,19 +38,6 @@ public static void Range([DoesNotReturnIf(false)] bool condition, string? messag } } - /// - /// 任务异常 - /// - /// 任务结果类型 - /// 异常消息 - /// 异常的任务 - [SuppressMessage("", "VSTHRD200")] - public static Task Fault(string message) - { - InvalidOperationException exception = new(message); - return Task.FromException(exception); - } - /// /// Unconditionally throws an . /// diff --git a/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest b/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest index eb02f63f0a..5dcd809687 100644 --- a/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest +++ b/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest @@ -12,7 +12,7 @@ + Version="1.2.5.0" /> 胡桃 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs index 9de0e456a8..094c4d226d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs @@ -109,7 +109,7 @@ public async ValueTask RefreshDailyNotesAsync(bool notify) // cache await ThreadHelper.SwitchToMainThreadAsync(); - entries?.Single(e => e.UserId == entry.UserId && e.Uid == entry.Uid).UpdateDailyNote(dailyNote); + entries?.SingleOrDefault(e => e.UserId == entry.UserId && e.Uid == entry.Uid)?.UpdateDailyNote(dailyNote); if (notify) { diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Locator/IGameLocator.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Locator/IGameLocator.cs index e65c2c73c4..5055bd4543 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Locator/IGameLocator.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Locator/IGameLocator.cs @@ -22,5 +22,6 @@ internal interface IGameLocator : INamed /// 路径应当包含启动器文件名称 /// /// 游戏启动器位置 + [Obsolete("不应定位启动器位置")] Task> LocateLauncherPathAsync(); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/InfoBarService.cs b/src/Snap.Hutao/Snap.Hutao/Service/InfoBarService.cs index 58dd762041..f684ad305f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/InfoBarService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/InfoBarService.cs @@ -3,6 +3,8 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; +using Microsoft.Xaml.Interactivity; +using Snap.Hutao.Control.Behavior; using Snap.Hutao.Service.Abstraction; namespace Snap.Hutao.Service; diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml b/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml index e642b2ff8b..2c0e8b7098 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml @@ -1,13 +1,17 @@ - + Closed="OnContentDialogClosed" + Style="{StaticResource DefaultContentDialogStyle}" + Title="米游社每日签到" + PrimaryButtonText="完成" + DefaultButton="Primary"> - - + + diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs index 85c71a9011..3018f04443 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs @@ -1,16 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using Microsoft.Extensions.DependencyInjection; using Microsoft.UI.Xaml.Controls; using Microsoft.Web.WebView2.Core; using Snap.Hutao.Model.Binding.User; -using Snap.Hutao.Service.Abstraction; using Snap.Hutao.Service.User; using Snap.Hutao.Web.Bridge; -using Snap.Hutao.Web.Bridge.Model; -using Snap.Hutao.Web.Bridge.Model.Event; -using Snap.Hutao.Web.Hoyolab.DynamicSecret; -using Windows.UI.Popups; namespace Snap.Hutao.View.Dialog; @@ -19,6 +15,10 @@ namespace Snap.Hutao.View.Dialog; /// public sealed partial class SignInWebViewDialog : ContentDialog { + private readonly IServiceScope scope; + [SuppressMessage("", "IDE0052")] + private SignInJsInterface? signInJsInterface; + /// /// һµǩҳͼԻ /// @@ -27,6 +27,7 @@ public SignInWebViewDialog(MainWindow window) { InitializeComponent(); XamlRoot = window.Content.XamlRoot; + scope = Ioc.Default.CreateScope(); } private void OnGridLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) @@ -38,31 +39,27 @@ private async Task InitializeAsync() { await WebView.EnsureCoreWebView2Async(); CoreWebView2 coreWebView2 = WebView.CoreWebView2; - IUserService userService = Ioc.Default.GetRequiredService(); - IInfoBarService infoBarService = Ioc.Default.GetRequiredService(); - ILogger logger = Ioc.Default.GetRequiredService>(); + IUserService userService = scope.ServiceProvider.GetRequiredService(); + User? user = userService.Current; - coreWebView2.SetCookie(user?.CookieToken, user?.Ltoken); - coreWebView2.SetMobileUserAgent(); - coreWebView2.InitializeBridge(logger, false) - .Register(e => Hide()) - .Register(e => infoBarService.Information("޷ʹô˹", "ǰʵ֤")) - .Register(s => s.Callback(result => result.Data["statusBarHeight"] = 0)) - .Register(s => s.Callback(result => - { - result.Data["DS"] = DynamicSecretHandler.GetDynamicSecret(nameof(SaltType.K2), nameof(DynamicSecretVersion.Gen1), includeChars: true); - })) - .Register(s => s.Callback(result => - { - result.Data["id"] = "111"; - result.Data["gender"] = 0; - result.Data["nickname"] = "222"; - result.Data["introduce"] = "333"; - result.Data["avatar_url"] = "https://img-static.mihoyo.com/communityweb/upload/52de23f1b1a060e4ccaa8b24c1305dd9.png"; - })); + if (user == null) + { + return; + } + + coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent(); + signInJsInterface = new(coreWebView2, scope.ServiceProvider); +#if DEBUG coreWebView2.OpenDevToolsWindow(); +#endif coreWebView2.Navigate("https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501"); } + + private void OnContentDialogClosed(ContentDialog sender, ContentDialogClosedEventArgs args) + { + signInJsInterface = null; + scope.Dispose(); + } } diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml index a94dcace32..18116a9a87 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml @@ -61,6 +61,16 @@ Icon="" Header="胡桃" Description="{Binding AppVersion}"/> + + + + + + Icon="" + Header="米游社每日签到"> + + + + + +