diff --git a/src/Snap.Hutao/SettingsUI/SettingsUI.csproj b/src/Snap.Hutao/SettingsUI/SettingsUI.csproj index cd2d5439..630184f0 100644 --- a/src/Snap.Hutao/SettingsUI/SettingsUI.csproj +++ b/src/Snap.Hutao/SettingsUI/SettingsUI.csproj @@ -1,7 +1,7 @@  - net7.0-windows10.0.17763.0 - 10.0.17763.0 + net7.0-windows10.0.18362.0 + 10.0.18362.0 SettingsUI x64 win10-x64 @@ -11,7 +11,7 @@ - + diff --git a/src/Snap.Hutao/Snap.Hutao.Installer/Snap.Hutao.Installer.csproj b/src/Snap.Hutao/Snap.Hutao.Installer/Snap.Hutao.Installer.csproj index 559a87e9..8371371b 100644 --- a/src/Snap.Hutao/Snap.Hutao.Installer/Snap.Hutao.Installer.csproj +++ b/src/Snap.Hutao/Snap.Hutao.Installer/Snap.Hutao.Installer.csproj @@ -8,6 +8,7 @@ true app.manifest embedded + AnyCPU;x64 diff --git a/src/Snap.Hutao/Snap.Hutao.sln b/src/Snap.Hutao/Snap.Hutao.sln index abd0020d..1353fa07 100644 --- a/src/Snap.Hutao/Snap.Hutao.sln +++ b/src/Snap.Hutao/Snap.Hutao.sln @@ -14,7 +14,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsUI", "SettingsUI\Se EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.SourceGeneration", "Snap.Hutao.SourceGeneration\Snap.Hutao.SourceGeneration.csproj", "{8B96721E-5604-47D2-9B72-06FEBAD0CE00}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snap.Hutao.Installer", "Snap.Hutao.Installer\Snap.Hutao.Installer.csproj", "{CEC01691-F65E-4874-9AE2-F571369A7631}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.Installer", "Snap.Hutao.Installer\Snap.Hutao.Installer.csproj", "{CEC01691-F65E-4874-9AE2-F571369A7631}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -88,8 +88,8 @@ Global {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|Any CPU.Build.0 = Debug|Any CPU {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|arm64.ActiveCfg = Debug|Any CPU {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|arm64.Build.0 = Debug|Any CPU - {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|x64.ActiveCfg = Debug|Any CPU - {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|x64.Build.0 = Debug|Any CPU + {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|x64.ActiveCfg = Debug|x64 + {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|x64.Build.0 = Debug|x64 {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|x86.ActiveCfg = Debug|Any CPU {CEC01691-F65E-4874-9AE2-F571369A7631}.Debug|x86.Build.0 = Debug|Any CPU {CEC01691-F65E-4874-9AE2-F571369A7631}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/Snap.Hutao/Snap.Hutao/App.xaml.cs b/src/Snap.Hutao/Snap.Hutao/App.xaml.cs index 24272c01..57ffc0b8 100644 --- a/src/Snap.Hutao/Snap.Hutao/App.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/App.xaml.cs @@ -1,14 +1,13 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using CommunityToolkit.WinUI.Notifications; using Microsoft.UI.Xaml; using Microsoft.Windows.AppLifecycle; using Snap.Hutao.Core; using Snap.Hutao.Core.Exception; using Snap.Hutao.Core.LifeCycle; using Snap.Hutao.Core.Logging; -using Snap.Hutao.Extension; -using Snap.Hutao.Service.Metadata; using System.Diagnostics; using Windows.Storage; @@ -48,6 +47,7 @@ public partial class App : Application // manually invoke Activation.Activate(firstInstance, activatedEventArgs); firstInstance.Activated += Activation.Activate; + ToastNotificationManagerCompat.OnActivated += Activation.NotificationActivate; logger.LogInformation(EventIds.CommonLog, "Snap Hutao | {name} : {version}", CoreEnvironment.FamilyName, CoreEnvironment.Version); logger.LogInformation(EventIds.CommonLog, "Cache folder : {folder}", ApplicationData.Current.TemporaryFolder.Path); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs index faf56d30..c25f8fc4 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/Activation.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using CommunityToolkit.WinUI.Notifications; using Microsoft.Windows.AppLifecycle; using Snap.Hutao.Extension; using Snap.Hutao.Service.Abstraction; @@ -45,7 +46,29 @@ internal static class Activation public static void Activate(object? sender, AppActivationArguments args) { _ = sender; - HandleActivationAsync(args).SafeForget(); + if (!ToastNotificationManagerCompat.WasCurrentProcessToastActivated()) + { + HandleActivationAsync(args).SafeForget(); + } + } + + /// + /// 响应通知激活事件 + /// + /// 参数 + public static void NotificationActivate(ToastNotificationActivatedEventArgsCompat args) + { + ToastArguments toastArgs = ToastArguments.Parse(args.Argument); + _ = toastArgs; + + if (toastArgs.TryGetValue("Action", out string? action)) + { + if (action == LaunchGame) + { + _ = toastArgs.TryGetValue("Uid", out string? uid); + HandleLaunchGameActionAsync(uid).SafeForget(); + } + } } /// @@ -87,18 +110,7 @@ internal static class Activation case LaunchGame: { - await ThreadHelper.SwitchToMainThreadAsync(); - if (!MainWindow.IsPresent) - { - _ = Ioc.Default.GetRequiredService(); - } - else - { - await Ioc.Default - .GetRequiredService() - .NavigateAsync(INavigationAwaiter.Default, true).ConfigureAwait(false); - } - + await HandleLaunchGameActionAsync().ConfigureAwait(false); break; } } @@ -108,6 +120,7 @@ internal static class Activation private static async Task WaitMainWindowAsync() { + await ThreadHelper.SwitchToMainThreadAsync(); _ = Ioc.Default.GetRequiredService(); await Ioc.Default.GetRequiredService().WaitInitializationAsync().ConfigureAwait(false); @@ -177,4 +190,21 @@ internal static class Activation } } } + + private static async Task HandleLaunchGameActionAsync(string? uid = null) + { + await ThreadHelper.SwitchToMainThreadAsync(); + + // TODO auto switch to account + if (!MainWindow.IsPresent) + { + _ = Ioc.Default.GetRequiredService(); + } + else + { + await Ioc.Default + .GetRequiredService() + .NavigateAsync(INavigationAwaiter.Default, true).ConfigureAwait(false); + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest b/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest index c51aa94c..1343a625 100644 --- a/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest +++ b/src/Snap.Hutao/Snap.Hutao/Package.appxmanifest @@ -2,15 +2,17 @@ + xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" + IgnorableNamespaces="com uap desktop desktop6 rescap"> + Version="1.2.0.0" /> 胡桃 @@ -22,7 +24,7 @@ - + @@ -43,6 +45,16 @@ + + + + + + + + + + 胡桃 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/ReliquaryWeightConfiguration.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/ReliquaryWeightConfiguration.cs index b370c247..a9453609 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/ReliquaryWeightConfiguration.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/ReliquaryWeightConfiguration.cs @@ -83,5 +83,6 @@ internal static partial class ReliquaryWeightConfiguration new(AvatarIds.Nilou, 100, 75, 0, 100, 100, 0, 55, 0, "反应流") { { FightProperty.FIGHT_PROP_WATER_ADD_HURT, 100 } }, new(AvatarIds.Cyno, 0, 75, 0, 100, 100, 75, 55, 0) { { FightProperty.FIGHT_PROP_ELEC_ADD_HURT, 100 } }, new(AvatarIds.Candace, 100, 75, 0, 100, 100, 0, 55, 0) { { FightProperty.FIGHT_PROP_WATER_ADD_HURT, 100 } }, + new(AvatarIds.Nahida, 0, 55, 0, 100, 100, 100, 55, 0) { { FightProperty.FIGHT_PROP_GRASS_ADD_HURT, 100 } }, }; } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs index c3d24629..7d725ae7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.WinUI.Notifications; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Snap.Hutao.Context.Database; @@ -11,6 +12,7 @@ using Snap.Hutao.Message; using Snap.Hutao.Model.Binding.User; using Snap.Hutao.Model.Entity; using Snap.Hutao.Service.User; +using Snap.Hutao.Web.Hoyolab.Takumi.Binding; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote; using System.Collections.ObjectModel; @@ -96,6 +98,7 @@ internal class DailyNoteService : IDailyNoteService, IRecipient(); GameRecordClient gameRecordClient = scope.ServiceProvider.GetRequiredService(); + BindingClient bindingClient = scope.ServiceProvider.GetRequiredService(); foreach (DailyNoteEntry entry in appDbContext.DailyNotes.Include(n => n.User)) { @@ -111,7 +114,7 @@ internal class DailyNoteService : IDailyNoteService, IRecipient hints = new(); - if (!entry.ResinNotifySuppressed && entry.DailyNote.CurrentResin >= entry.ResinNotifyThreshold) + + // NotifySuppressed judge { - hints.Add($"当前原粹树脂:{entry.DailyNote.CurrentResin}"); - entry.ResinNotifySuppressed = true; + if (entry.DailyNote.CurrentResin >= entry.ResinNotifyThreshold) + { + if (!entry.ResinNotifySuppressed) + { + hints.Add($"当前原粹树脂:{entry.DailyNote.CurrentResin}"); + entry.ResinNotifySuppressed = true; + } + } + else + { + entry.ResinNotifySuppressed = false; + } + + if (entry.DailyNote.CurrentHomeCoin >= entry.HomeCoinNotifyThreshold) + { + if (!entry.HomeCoinNotifySuppressed) + { + hints.Add($"当前洞天宝钱:{entry.DailyNote.CurrentHomeCoin}"); + entry.HomeCoinNotifySuppressed = true; + } + } + else + { + entry.HomeCoinNotifySuppressed = false; + } + + if (entry.DailyTaskNotify && !entry.DailyNote.IsExtraTaskRewardReceived) + { + if (!entry.DailyTaskNotifySuppressed) + { + hints.Add(entry.DailyNote.ExtraTaskRewardDescription); + entry.DailyTaskNotifySuppressed = true; + } + } + else + { + entry.DailyTaskNotifySuppressed = false; + } + + if (entry.TransformerNotify && entry.DailyNote.Transformer.Obtained && entry.DailyNote.Transformer.RecoveryTime.Reached) + { + if (!entry.TransformerNotifySuppressed) + { + hints.Add("参量质变仪已准备完成"); + entry.TransformerNotifySuppressed = true; + } + } + else + { + entry.TransformerNotifySuppressed = false; + } + + if (entry.ExpeditionNotify && entry.DailyNote.Expeditions.All(e => e.Status == ExpeditionStatus.Finished)) + { + if (!entry.ExpeditionNotifySuppressed) + { + hints.Add("探索派遣已完成"); + entry.ExpeditionNotifySuppressed = true; + } + } + else + { + entry.ExpeditionNotifySuppressed = false; + } } - if (!entry.HomeCoinNotifySuppressed && entry.DailyNote.CurrentHomeCoin >= entry.HomeCoinNotifyThreshold) + if (hints.Count <= 0) { - hints.Add($"当前洞天宝钱:{entry.DailyNote.CurrentHomeCoin}"); - entry.HomeCoinNotifySuppressed = true; + return; } - if (!entry.DailyTaskNotifySuppressed && entry.DailyTaskNotify && !entry.DailyNote.IsExtraTaskRewardReceived) + List roles = await client.GetUserGameRolesAsync(entry.User).ConfigureAwait(false); + string attribution = roles.SingleOrDefault(r => r.GameUid == entry.Uid)?.ToString() ?? "未知角色"; + + ToastContentBuilder builder = new ToastContentBuilder() + .AddHeader("DAILYNOTE", "实时便笺提醒", "DAILYNOTE") + .AddAttributionText(attribution) + .AddButton(new ToastButton().SetContent("开始游戏").AddArgument("Action", "LaunchGame").AddArgument("Uid", entry.Uid)) + .AddButton(new ToastButtonDismiss("我知道了")); + + using (IServiceScope scope = scopeFactory.CreateScope()) { - hints.Add(entry.DailyNote.ExtraTaskRewardDescription); - entry.DailyTaskNotifySuppressed = true; + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + if (appDbContext.Settings.SingleOrAdd(SettingEntry.DailyNoteReminderNotify, false.ToString()).GetBoolean()) + { + builder.SetToastScenario(ToastScenario.Reminder); + } } - if (!entry.TransformerNotifySuppressed && entry.TransformerNotify && entry.DailyNote.Transformer.Obtained && entry.DailyNote.Transformer.RecoveryTime.Reached) + if (hints.Count > 2) { - hints.Add("参量质变仪已准备完成"); - entry.TransformerNotifySuppressed = true; + builder.AddText("多个提醒项达到设定值"); + } + else + { + foreach (string hint in hints) + { + builder.AddText(hint); + } } - if (!entry.ExpeditionNotifySuppressed && entry.ExpeditionNotify && entry.DailyNote.Expeditions.All(e => e.Status == ExpeditionStatus.Finished)) - { - hints.Add("探索派遣已完成"); - entry.ExpeditionNotifySuppressed = true; - } + await ThreadHelper.SwitchToMainThreadAsync(); + builder.Show(); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj index ffe7248c..7a791ac9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj +++ b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj @@ -20,7 +20,7 @@ True F8C2255969BEA4A681CED102771BF807856AEC02 SHA256 - True + False True True Never @@ -145,7 +145,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs index 5f4aef23..c8414a61 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs @@ -38,7 +38,18 @@ internal class BindingClient /// 用户 /// 取消令牌 /// 用户角色信息 - public async Task> GetUserGameRolesAsync(User user, CancellationToken token = default) + public Task> GetUserGameRolesAsync(User user, CancellationToken token = default) + { + return GetUserGameRolesAsync(user.Entity, token); + } + + /// + /// 获取用户角色信息 + /// + /// 用户 + /// 取消令牌 + /// 用户角色信息 + public async Task> GetUserGameRolesAsync(Model.Entity.User user, CancellationToken token = default) { Response>? resp = await httpClient .SetUser(user) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/DailyNote/Expedition.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/DailyNote/Expedition.cs index 3d7b1bea..26d14229 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/DailyNote/Expedition.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/DailyNote/Expedition.cs @@ -14,7 +14,7 @@ public class Expedition private const string Keqing = "https://upload-bbs.mihoyo.com/game_record/genshin/character_side_icon/UI_AvatarIcon_Side_Keqing.png"; private const string Sara = "https://upload-bbs.mihoyo.com/game_record/genshin/character_side_icon/UI_AvatarIcon_Side_Sara.png"; - private static readonly List ShortExpeditionTimeAvatars = new List() + private static readonly List ShortExpeditionTimeAvatars = new() { Bennett, Chongyun, Fischl, Keqing, Sara, };