From 168bed4b2cd41c93cbd6d790353f952e465c6335 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Tue, 16 May 2023 15:32:44 +0800 Subject: [PATCH] shell interop --- .../HttpClientGenerator.cs | 29 +-- src/Snap.Hutao/Snap.Hutao/App.xaml.cs | 9 +- .../Snap.Hutao/Core/Shell/IJumpListInterop.cs | 16 ++ .../Core/Shell/IScheduleTaskInterop.cs | 23 +++ .../JumpListInterop.cs} | 9 +- .../ScheduleTaskInterop.cs} | 13 +- .../Service/DailyNote/DailyNoteOptions.cs | 6 +- .../Service/Metadata/IMetadataService.cs | 165 ++++++++++-------- 8 files changed, 148 insertions(+), 122 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Core/Shell/IJumpListInterop.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Core/Shell/IScheduleTaskInterop.cs rename src/Snap.Hutao/Snap.Hutao/Core/{JumpListHelper.cs => Shell/JumpListInterop.cs} (79%) rename src/Snap.Hutao/Snap.Hutao/Core/{ScheduleTaskHelper.cs => Shell/ScheduleTaskInterop.cs} (88%) diff --git a/src/Snap.Hutao/Snap.Hutao.SourceGeneration/DependencyInjection/HttpClientGenerator.cs b/src/Snap.Hutao/Snap.Hutao.SourceGeneration/DependencyInjection/HttpClientGenerator.cs index d6c888bc..753398c4 100644 --- a/src/Snap.Hutao/Snap.Hutao.SourceGeneration/DependencyInjection/HttpClientGenerator.cs +++ b/src/Snap.Hutao/Snap.Hutao.SourceGeneration/DependencyInjection/HttpClientGenerator.cs @@ -19,17 +19,11 @@ internal sealed class HttpClientGenerator : IIncrementalGenerator { private const string AttributeName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientAttribute"; - private const string DefaultName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.Default"; - private const string XRpcName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.XRpc"; - private const string XRpc2Name = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.XRpc2"; - private const string XRpc3Name = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.XRpc3"; - + private const string HttpClientConfiguration = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration."; private const string PrimaryHttpMessageHandlerAttributeName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.PrimaryHttpMessageHandlerAttribute"; private const string UseDynamicSecretAttributeName = "Snap.Hutao.Web.Hoyolab.DynamicSecret.UseDynamicSecretAttribute"; private const string CRLF = "\r\n"; - private static readonly DiagnosticDescriptor invalidConfigurationDescriptor = new("SH100", "无效的 HttpClientConfiguration", "尚未支持生成 {0} 配置", "Quality", DiagnosticSeverity.Error, true); - public void Initialize(IncrementalGeneratorInitializationContext context) { IncrementalValueProvider> injectionClasses = context.SyntaxProvider @@ -109,26 +103,7 @@ internal sealed class HttpClientGenerator : IIncrementalGenerator } lineBuilder.Append($"{context.Symbol.ToDisplayString()}>("); - - string configurationName = arguments[0].ToCSharpString(); - switch (configurationName) - { - case DefaultName: - lineBuilder.Append("DefaultConfiguration)"); - break; - case XRpcName: - lineBuilder.Append("XRpcConfiguration)"); - break; - case XRpc2Name: - lineBuilder.Append("XRpc2Configuration)"); - break; - case XRpc3Name: - lineBuilder.Append("XRpc3Configuration)"); - break; - default: - production.ReportDiagnostic(Diagnostic.Create(invalidConfigurationDescriptor, null, configurationName)); - break; - } + lineBuilder.Append(arguments[0].ToCSharpString().Substring(HttpClientConfiguration.Length)).Append("Configuration)"); if (context.SingleOrDefaultAttribute(PrimaryHttpMessageHandlerAttributeName) is AttributeData handlerData) { diff --git a/src/Snap.Hutao/Snap.Hutao/App.xaml.cs b/src/Snap.Hutao/Snap.Hutao/App.xaml.cs index 7020538b..01024e88 100644 --- a/src/Snap.Hutao/Snap.Hutao/App.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/App.xaml.cs @@ -1,12 +1,12 @@ // 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.ExceptionService; using Snap.Hutao.Core.LifeCycle; +using Snap.Hutao.Core.Shell; using System.Diagnostics; namespace Snap.Hutao; @@ -56,7 +56,7 @@ public sealed partial class App : Application activation.InitializeWith(firstInstance); LogDiagnosticInformation(); - PostLaunchAsync().SafeForget(logger); + serviceProvider.GetRequiredService().ConfigureAsync().SafeForget(); } else { @@ -72,11 +72,6 @@ public sealed partial class App : Application } } - private static async Task PostLaunchAsync() - { - await JumpListHelper.ConfigureAsync().ConfigureAwait(false); - } - private void LogDiagnosticInformation() { HutaoOptions hutaoOptions = serviceProvider.GetRequiredService(); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Shell/IJumpListInterop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/IJumpListInterop.cs new file mode 100644 index 00000000..73d8bc9d --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/IJumpListInterop.cs @@ -0,0 +1,16 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Core.Shell; + +/// +/// 跳转列表交互 +/// +internal interface IJumpListInterop +{ + /// + /// 异步配置跳转列表 + /// + /// 任务 + Task ConfigureAsync(); +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Shell/IScheduleTaskInterop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/IScheduleTaskInterop.cs new file mode 100644 index 00000000..9a7627a5 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/IScheduleTaskInterop.cs @@ -0,0 +1,23 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Core.Shell; + +/// +/// 任务计划互操作 +/// +internal interface IScheduleTaskInterop +{ + /// + /// 注册实时便笺刷新任务 + /// + /// 间隔(秒) + /// 是否注册或修改成功 + bool RegisterForDailyNoteRefresh(int interval); + + /// + /// 卸载全部注册的任务 + /// + /// 是否卸载成功 + bool UnregisterAllTasks(); +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/JumpListHelper.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/JumpListInterop.cs similarity index 79% rename from src/Snap.Hutao/Snap.Hutao/Core/JumpListHelper.cs rename to src/Snap.Hutao/Snap.Hutao/Core/Shell/JumpListInterop.cs index a66a53cf..3cbda37c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/JumpListHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/JumpListInterop.cs @@ -4,19 +4,20 @@ using Snap.Hutao.Core.LifeCycle; using Windows.UI.StartScreen; -namespace Snap.Hutao.Core; +namespace Snap.Hutao.Core.Shell; /// -/// 跳转列表帮助类 +/// 跳转列表交互 /// [HighQuality] -internal static class JumpListHelper +[Injection(InjectAs.Transient, typeof(IJumpListInterop))] +internal sealed class JumpListInterop : IJumpListInterop { /// /// 异步配置跳转列表 /// /// 任务 - public static async Task ConfigureAsync() + public async Task ConfigureAsync() { if (JumpList.IsSupported()) { diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ScheduleTaskHelper.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ScheduleTaskInterop.cs similarity index 88% rename from src/Snap.Hutao/Snap.Hutao/Core/ScheduleTaskHelper.cs rename to src/Snap.Hutao/Snap.Hutao/Core/Shell/ScheduleTaskInterop.cs index 1396090c..dd82d68b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/ScheduleTaskHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ScheduleTaskInterop.cs @@ -6,13 +6,14 @@ using System.IO; using System.Runtime.InteropServices; using Windows.Storage; -namespace Snap.Hutao.Core; +namespace Snap.Hutao.Core.Shell; /// -/// 任务计划器服务 +/// 任务计划互操作 /// [HighQuality] -internal static class ScheduleTaskHelper +[Injection(InjectAs.Transient, typeof(IScheduleTaskInterop))] +internal sealed class ScheduleTaskInterop : IScheduleTaskInterop { private const string DailyNoteRefreshTaskName = "SnapHutaoDailyNoteRefreshTask"; @@ -21,7 +22,7 @@ internal static class ScheduleTaskHelper /// /// 间隔(秒) /// 是否注册或修改成功 - public static bool RegisterForDailyNoteRefresh(int interval) + public bool RegisterForDailyNoteRefresh(int interval) { try { @@ -43,7 +44,7 @@ internal static class ScheduleTaskHelper /// 卸载全部注册的任务 /// /// 是否卸载成功 - public static bool UnregisterAllTasks() + public bool UnregisterAllTasks() { try { @@ -74,4 +75,4 @@ internal static class ScheduleTaskHelper return fullName; } -} +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs index d04fd2f0..b0232f39 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Snap.Hutao.Core; +using Snap.Hutao.Core.Shell; using Snap.Hutao.Model; using Snap.Hutao.Model.Entity; using Snap.Hutao.Service.Abstraction; @@ -16,6 +16,7 @@ namespace Snap.Hutao.Service.DailyNote; internal sealed class DailyNoteOptions : DbStoreOptions { private readonly IServiceProvider serviceProvider; + private readonly IScheduleTaskInterop scheduleTaskInterop; private readonly List> refreshTimes = new() { new(SH.ViewModelDailyNoteRefreshTime4, 240), @@ -36,6 +37,7 @@ internal sealed class DailyNoteOptions : DbStoreOptions public DailyNoteOptions(IServiceProvider serviceProvider) : base(serviceProvider) { + scheduleTaskInterop = serviceProvider.GetRequiredService(); this.serviceProvider = serviceProvider; } @@ -54,7 +56,7 @@ internal sealed class DailyNoteOptions : DbStoreOptions { if (value != null) { - if (ScheduleTaskHelper.RegisterForDailyNoteRefresh(value.Value)) + if (scheduleTaskInterop.RegisterForDailyNoteRefresh(value.Value)) { SetOption(ref selectedRefreshTime, SettingEntry.DailyNoteRefreshSeconds, value, value => value.Value.ToString()); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Metadata/IMetadataService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Metadata/IMetadataService.cs index d9bd0e4f..c7d3406d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Metadata/IMetadataService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Metadata/IMetadataService.cs @@ -18,6 +18,7 @@ namespace Snap.Hutao.Service.Metadata; /// 元数据服务 /// [HighQuality] +[SuppressMessage("", "SA1124")] internal interface IMetadataService : ICastableService { /// @@ -26,6 +27,8 @@ internal interface IMetadataService : ICastableService /// 初始化是否成功 ValueTask InitializeAsync(); + #region RawData + /// /// 异步获取成就列表 /// @@ -40,6 +43,13 @@ internal interface IMetadataService : ICastableService /// 成就分类列表 ValueTask> GetAchievementGoalsAsync(CancellationToken token = default); + /// + /// 异步获取角色突破列表 + /// + /// 取消令牌 + /// 角色突破列表 + ValueTask> GetAvatarPromotesAsync(CancellationToken token = default); + /// /// 异步获取角色列表 /// @@ -47,13 +57,6 @@ internal interface IMetadataService : ICastableService /// 角色列表 ValueTask> GetAvatarsAsync(CancellationToken token = default); - /// - /// 异步获取装备被动Id到圣遗物套装的映射 - /// - /// 取消令牌 - /// 装备被动Id到圣遗物套装的映射 - ValueTask> GetEquipAffixIdToReliquarySetMapAsync(CancellationToken token = default); - /// /// 异步获取卡池配置列表 /// @@ -61,6 +64,79 @@ internal interface IMetadataService : ICastableService /// 卡池配置列表 ValueTask> GetGachaEventsAsync(CancellationToken token = default); + /// + /// 异步获取材料列表 + /// + /// 取消令牌 + /// 材料列表 + ValueTask> GetMaterialsAsync(CancellationToken token = default); + + /// + /// 异步获取怪物列表 + /// + /// 取消令牌 + /// 怪物列表 + ValueTask> GetMonstersAsync(CancellationToken token = default); + + /// + /// 异步获取圣遗物列表 + /// + /// 取消令牌 + /// 圣遗物列表 + ValueTask> GetReliquariesAsync(CancellationToken token = default); + + /// + /// 异步获取圣遗物强化属性列表 + /// + /// 取消令牌 + /// 圣遗物强化属性列表 + ValueTask> GetReliquaryAffixesAsync(CancellationToken token = default); + + /// + /// 异步获取圣遗物等级数据 + /// + /// 取消令牌 + /// 圣遗物等级数据 + ValueTask> GetReliquaryLevelsAsync(CancellationToken token = default); + + /// + /// 异步获取圣遗物主属性强化属性列表 + /// + /// 取消令牌 + /// 圣遗物强化属性列表 + ValueTask> GetReliquaryMainAffixesAsync(CancellationToken token = default); + + /// + /// 异步获取圣遗物套装 + /// + /// 取消令牌 + /// 圣遗物套装列表 + ValueTask> GetReliquarySetsAsync(CancellationToken token = default); + + /// + /// 异步获取武器突破列表 + /// + /// 取消令牌 + /// 武器突破列表 + ValueTask> GetWeaponPromotesAsync(CancellationToken token = default); + + /// + /// 异步获取武器列表 + /// + /// 取消令牌 + /// 武器列表 + ValueTask> GetWeaponsAsync(CancellationToken token = default); + #endregion + + #region IdDataMap + + /// + /// 异步获取装备被动Id到圣遗物套装的映射 + /// + /// 取消令牌 + /// 装备被动Id到圣遗物套装的映射 + ValueTask> GetEquipAffixIdToReliquarySetMapAsync(CancellationToken token = default); + /// /// 异步获取成就映射 /// @@ -109,6 +185,9 @@ internal interface IMetadataService : ICastableService /// 取消令牌 /// Id到武器的字典 ValueTask> GetIdToWeaponMapAsync(CancellationToken token = default); + #endregion + + #region NameDataMap /// /// 异步获取名称到角色的字典 @@ -123,62 +202,9 @@ internal interface IMetadataService : ICastableService /// 取消令牌 /// 名称到武器的字典 ValueTask> GetNameToWeaponMapAsync(CancellationToken token = default); + #endregion - /// - /// 异步获取圣遗物列表 - /// - /// 取消令牌 - /// 圣遗物列表 - ValueTask> GetReliquariesAsync(CancellationToken token = default); - - /// - /// 异步获取圣遗物强化属性列表 - /// - /// 取消令牌 - /// 圣遗物强化属性列表 - ValueTask> GetReliquaryAffixesAsync(CancellationToken token = default); - - /// - /// 异步获取圣遗物等级数据 - /// - /// 取消令牌 - /// 圣遗物等级数据 - ValueTask> GetReliquaryLevelsAsync(CancellationToken token = default); - - /// - /// 异步获取圣遗物主属性强化属性列表 - /// - /// 取消令牌 - /// 圣遗物强化属性列表 - ValueTask> GetReliquaryMainAffixesAsync(CancellationToken token = default); - - /// - /// 异步获取武器列表 - /// - /// 取消令牌 - /// 武器列表 - ValueTask> GetWeaponsAsync(CancellationToken token = default); - - /// - /// 异步获取圣遗物套装 - /// - /// 取消令牌 - /// 圣遗物套装列表 - ValueTask> GetReliquarySetsAsync(CancellationToken token = default); - - /// - /// 异步获取材料列表 - /// - /// 取消令牌 - /// 材料列表 - ValueTask> GetMaterialsAsync(CancellationToken token = default); - - /// - /// 异步获取怪物列表 - /// - /// 取消令牌 - /// 怪物列表 - ValueTask> GetMonstersAsync(CancellationToken token = default); + #region LevelCurveMap /// /// 异步获取等级角色曲线映射 @@ -200,18 +226,5 @@ internal interface IMetadataService : ICastableService /// 取消令牌 /// 等级武器曲线映射 ValueTask>> GetLevelToWeaponCurveMapAsync(CancellationToken token = default); - - /// - /// 异步获取角色突破列表 - /// - /// 取消令牌 - /// 角色突破列表 - ValueTask> GetAvatarPromotesAsync(CancellationToken token = default); - - /// - /// 异步获取武器突破列表 - /// - /// 取消令牌 - /// 武器突破列表 - ValueTask> GetWeaponPromotesAsync(CancellationToken token = default); + #endregion } \ No newline at end of file