XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

HaloPixelToolBox

【WinUI3】基于USB HID通讯的花再音响工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using HaloPixelToolBox.Client.Utilities;
using HaloPixelToolBox.Core.Models.Notifications;
using Windows.UI.Notifications.Management;

namespace HaloPixelToolBox.Client.Test;

internal class DesktopMessageReaderTests
{
    [SMTest]
    public static void QQDoesNotQueryClientWindow()
    {
        var requested = false;
        var reader = new DesktopMessageReader(_ => { requested = true; return []; });
        var result = reader.ReadAsync(MessageNotificationSource.QQ,
            [new(MessageNotificationSource.QQ, 0, true)], CancellationToken.None).GetAwaiter().GetResult();
        XFECode.Assert(!requested && !result.HasDetails, "QQ 详情必须通过 Windows 通知读取,不能访问 QQ 的无障碍提供程序");
        XFECode.Assert(reader.ReadPreviewsAsync(MessageNotificationSource.QQ, CancellationToken.None)
            .GetAwaiter().GetResult() is null, "QQ 主窗口不能参与无障碍轮询");
    }

    [SMTest]
    public static void ReadWindowsNotificationApi()
    {
        var options = new MessageNotificationOptions(true, true, true);
        var snapshot = new WindowsMessageNotificationReader().ReadAsync(options, CancellationToken.None).GetAwaiter().GetResult();
        XFECode.Assert(snapshot is not null, "Windows 标准通知接口读取超时");
        Console.WriteLine($"Windows 通知访问状态:{snapshot!.Access};聊天软件通知数量:{snapshot.Messages.Count}");
        XFECode.Assert(snapshot.Access is UserNotificationListenerAccessStatus.Allowed
            or UserNotificationListenerAccessStatus.Denied or UserNotificationListenerAccessStatus.Unspecified, "无效的通知访问状态");
    }
}