mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
refactor
This commit is contained in:
@@ -26,7 +26,6 @@ internal sealed class RuntimeOptions : IOptions<RuntimeOptions>
|
||||
private readonly string webView2Version = SH.CoreWebView2HelperVersionUndetected;
|
||||
|
||||
private bool? isElevated;
|
||||
private bool? isWindows11;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的胡桃选项
|
||||
@@ -98,12 +97,6 @@ internal sealed class RuntimeOptions : IOptions<RuntimeOptions>
|
||||
/// </summary>
|
||||
public bool IsElevated { get => isElevated ??= GetElevated(); }
|
||||
|
||||
/// <summary>
|
||||
/// 系统版本是否大于等于 Windows 11
|
||||
/// %programfiles(x86)%\Windows Kits\10\Platforms\UAP\10.0.22000.0\PreviousPlatforms.xml
|
||||
/// </summary>
|
||||
public bool Windows11OrHigher { get => isWindows11 ?? ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 14); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public RuntimeOptions Value { get => this; }
|
||||
|
||||
|
||||
14
src/Snap.Hutao/Snap.Hutao/Core/UniversalApiContract.cs
Normal file
14
src/Snap.Hutao/Snap.Hutao/Core/UniversalApiContract.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Windows.Foundation.Metadata;
|
||||
|
||||
namespace Snap.Hutao.Core;
|
||||
|
||||
internal static class UniversalApiContract
|
||||
{
|
||||
public static bool IsPresent(WindowsVersion version)
|
||||
{
|
||||
return ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", (ushort)version);
|
||||
}
|
||||
}
|
||||
67
src/Snap.Hutao/Snap.Hutao/Core/WindowsVersion.cs
Normal file
67
src/Snap.Hutao/Snap.Hutao/Core/WindowsVersion.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core;
|
||||
|
||||
internal enum WindowsVersion : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// 10.0.10240.0
|
||||
/// </summary>
|
||||
Windows10 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.10586.0
|
||||
/// </summary>
|
||||
Windows10NovemberUpdate = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.14393.0
|
||||
/// </summary>
|
||||
Windows10AnniversaryUpdate = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.15063.0
|
||||
/// </summary>
|
||||
Windows10CreatorsUpdate = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.16299.0
|
||||
/// </summary>
|
||||
Windows10FallCreatorsUpdate = 5,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.17134.0
|
||||
/// </summary>
|
||||
Windows10Version1803 = 6,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.17763.0
|
||||
/// </summary>
|
||||
Windows10Version1809 = 7,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.18362.0
|
||||
/// </summary>
|
||||
Windows10Version1903 = 8,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.19041.0
|
||||
/// </summary>
|
||||
Windows10Version2004 = 10,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.20348.0
|
||||
/// </summary>
|
||||
Windows10Version2104 = 12,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.22000.0
|
||||
/// </summary>
|
||||
Windows11 = 14,
|
||||
|
||||
/// <summary>
|
||||
/// 10.0.22621.0
|
||||
/// </summary>
|
||||
Windows11Version22H2 = 15,
|
||||
}
|
||||
@@ -17,7 +17,6 @@ internal sealed partial class PickerFactory : IPickerFactory
|
||||
private const string AnyType = "*";
|
||||
|
||||
private readonly MainWindow mainWindow;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public FileOpenPicker GetFileOpenPicker(PickerLocationId location, string commitButton, params string[] fileTypes)
|
||||
@@ -33,7 +32,7 @@ internal sealed partial class PickerFactory : IPickerFactory
|
||||
}
|
||||
|
||||
// below Windows 11
|
||||
if (!runtimeOptions.Windows11OrHigher)
|
||||
if (!UniversalApiContract.IsPresent(WindowsVersion.Windows11))
|
||||
{
|
||||
// https://github.com/microsoft/WindowsAppSDK/issues/2931
|
||||
picker.FileTypeFilter.Add(AnyType);
|
||||
@@ -65,7 +64,7 @@ internal sealed partial class PickerFactory : IPickerFactory
|
||||
FolderPicker picker = GetInitializedPicker<FolderPicker>();
|
||||
|
||||
// below Windows 11
|
||||
if (!runtimeOptions.Windows11OrHigher)
|
||||
if (!UniversalApiContract.IsPresent(WindowsVersion.Windows11))
|
||||
{
|
||||
// https://github.com/microsoft/WindowsAppSDK/issues/2931
|
||||
picker.FileTypeFilter.Add(AnyType);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Notifications;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.Game;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.Auth;
|
||||
@@ -18,6 +20,8 @@ namespace Snap.Hutao.Service.DailyNote;
|
||||
[HighQuality]
|
||||
internal sealed class DailyNoteNotifier
|
||||
{
|
||||
private const string ToastHeaderIdArgument = "DAILYNOTE";
|
||||
private const string ToastAttributionUnknown = "Unknown";
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly DailyNoteEntry entry;
|
||||
@@ -68,16 +72,16 @@ internal sealed class DailyNoteNotifier
|
||||
if (rolesResponse.IsOk())
|
||||
{
|
||||
List<UserGameRole> roles = rolesResponse.Data.List;
|
||||
attribution = roles.SingleOrDefault(r => r.GameUid == entry.Uid)?.ToString() ?? "Unknown";
|
||||
attribution = roles.SingleOrDefault(r => r.GameUid == entry.Uid)?.ToString() ?? ToastAttributionUnknown;
|
||||
}
|
||||
|
||||
ToastContentBuilder builder = new ToastContentBuilder()
|
||||
.AddHeader("DAILYNOTE", SH.ServiceDailyNoteNotifierTitle, "DAILYNOTE")
|
||||
.AddHeader(ToastHeaderIdArgument, SH.ServiceDailyNoteNotifierTitle, ToastHeaderIdArgument)
|
||||
.AddAttributionText(attribution)
|
||||
.AddButton(new ToastButton()
|
||||
.SetContent(SH.ServiceDailyNoteNotifierActionLaunchGameButton)
|
||||
.AddArgument(Core.LifeCycle.Activation.Action, Core.LifeCycle.Activation.LaunchGame)
|
||||
.AddArgument(Core.LifeCycle.Activation.Uid, entry.Uid))
|
||||
.AddArgument(Activation.Action, Activation.LaunchGame)
|
||||
.AddArgument(Activation.Uid, entry.Uid))
|
||||
.AddButton(new ToastButtonDismiss(SH.ServiceDailyNoteNotifierActionLaunchGameDismiss));
|
||||
|
||||
if (options.IsReminderNotification)
|
||||
@@ -90,7 +94,7 @@ internal sealed class DailyNoteNotifier
|
||||
builder.AddText(SH.ServiceDailyNoteNotifierMultiValueReached);
|
||||
|
||||
// Desktop and Mobile started supporting adaptive toasts in API contract 3 (Anniversary Update)
|
||||
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3))
|
||||
if (UniversalApiContract.IsPresent(WindowsVersion.Windows10AnniversaryUpdate))
|
||||
{
|
||||
AdaptiveGroup group = new();
|
||||
foreach (NotifyInfo info in notifyInfos)
|
||||
|
||||
Reference in New Issue
Block a user