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

HaloPixelToolBox

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

公开
关注 0 Fork 0 Star 0
UTF-8
using HaloPixelToolBox.Core.Models.Notifications;

namespace HaloPixelToolBox.Core.Utilities;

public static class MessageNotificationClassifier
{
    public static MessageNotificationSource? GetSource(string processName) =>
        Path.GetFileNameWithoutExtension(processName).ToLowerInvariant() switch
        {
            "wechat" or "weixin" => MessageNotificationSource.WeChat,
            "qq" => MessageNotificationSource.QQ,
            "wxwork" => MessageNotificationSource.WeCom,
            _ => null
        };

    public static string GetDisplayName(MessageNotificationSource source) => source switch
    {
        MessageNotificationSource.WeChat => "微信",
        MessageNotificationSource.QQ => "QQ",
        MessageNotificationSource.WeCom => "企业微信",
        _ => throw new ArgumentOutOfRangeException(nameof(source))
    };

    public static bool IsNotificationPopup(string windowClass, int width, int height, bool topmost)
    {
        if (width < 80 || height < 30 || width > 800 || height > 500)
            return false;

        // 微信 / 企业微信的消息弹窗,以及 QQ NT 的小型置顶通知窗口。
        var knownClass = windowClass.Contains("Notification", StringComparison.OrdinalIgnoreCase)
            || windowClass.Contains("Notify", StringComparison.OrdinalIgnoreCase)
            || windowClass.Contains("NewMsg", StringComparison.OrdinalIgnoreCase)
            || windowClass.Contains("Toast", StringComparison.OrdinalIgnoreCase);
        return knownClass || (topmost && width <= 600 && height <= 300
            && windowClass.Equals("Chrome_WidgetWin_1", StringComparison.OrdinalIgnoreCase));
    }
}