feat: Add MAA Task Notification System (Supporting DingTalk, Bark, Qmsg, and Custom Webhooks) #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This Pull Request introduces a comprehensive Task Notification System for MAA. This system is designed to provide immediate, buffered, and reliable status updates to users via multiple third-party channels (DingTalk, Bark, Qmsg, and Custom Webhook).
The core of the implementation relies on a highly decoupled
NotificationServicearchitecture to handle scheduling, buffering, and retries independently for each channel.Key Changes
New Files & Core Architecture (The Notification System):
MeoAsstMac/Services/Notification/NotificationManager.swift(New): The central scheduler. Handles log observation, buffering, throttling (sending a summary based on time interval), and dispatching logs to enabled services.MeoAsstMac/Services/Notification/NotificationService.swift(New): Defines the protocol that all services must conform to, ensuring standardization.DingTalkService.swift,BarkService.swift,QmsgService.swift, andCustomWebhookService.swift. Each file contains its own specific API request logic, failure counter, and auto-retry/disable mechanism.DingTalk Client & Security:
MeoAsstMac/Services/Notification/DingTalkBotClient.swift(New): A dedicated client to handle the complexity of the DingTalk API, including support for Markdown messages and HMAC-SHA256 signature generation (加签).Data & UI Integration:
MeoAsstMac/Model/MAAViewModel.swift: Adds new@AppStorageproperties and models (NotificationTriggers,CustomWebhookSettings,QmsgSettings) to store user configurations for all new features.MeoAsstMac/MeoAsstMacApp.swift: Integrates and initializes theNotificationManagerwith theMAAViewModelinstance at application startup.Custom Webhook Feature:
CustomWebhookService.swiftimplements support for users to provide a custom JSON Body template, allowing variable substitution for{title},{content}, and{time}.Files Affected
MeoAsstMac/MeoAsstMacApp.swiftMeoAsstMac/Model/MAAViewModel.swiftMeoAsstMac/Services/Notification/BarkService.swift(New Feature)MeoAsstMac/Services/Notification/CustomWebhookService.swift(New Feature)MeoAsstMac/Services/Notification/DingTalkBotClient.swift(New Feature)MeoAsstMac/Services/Notification/DingTalkService.swift(New Feature)MeoAsstMac/Services/Notification/NotificationManager.swift(New Feature)MeoAsstMac/Services/Notification/NotificationService.swift(New Feature)MeoAsstMac/Services/Notification/QmsgService.swift(New Feature)摘要
本次拉取请求(PR)引入了一个全面的 MAA 任务通知系统。该系统旨在通过多个第三方渠道(钉钉、Bark、Qmsg 和自定义 Webhook),为用户提供即时、缓冲和可靠的状态更新。
实现的核心是高度解耦的
NotificationService架构,它负责独立处理每个通道的调度、缓冲和重试逻辑。主要更改
新增文件和核心架构(通知系统):
MeoAsstMac/Services/Notification/NotificationManager.swift(新增):中央调度器。处理日志监听、缓冲、节流(按时间间隔发送摘要),并将日志分派给已启用的服务。MeoAsstMac/Services/Notification/NotificationService.swift(新增):定义了所有服务必须遵循的协议,确保了标准化。DingTalkService.swift、BarkService.swift、QmsgService.swift和CustomWebhookService.swift。每个文件包含各自特有的 API 请求逻辑、失败计数器 和 自动重试/禁用机制。钉钉客户端与安全性:
MeoAsstMac/Services/Notification/DingTalkBotClient.swift(新增):一个专用的客户端,用于处理钉钉 API 的复杂性,包括支持 Markdown 消息 和 HMAC-SHA256 签名 生成(加签)。数据和 UI 集成:
MeoAsstMac/Model/MAAViewModel.swift:新增了@AppStorage属性和模型 (NotificationTriggers,CustomWebhookSettings,QmsgSettings),用于存储所有新功能的用户配置。MeoAsstMac/MeoAsstMacApp.swift:在应用启动时,将NotificationManager与MAAViewModel实例集成并初始化。自定义 Webhook 功能:
CustomWebhookService.swift实现了对用户提供自定义 JSON Body 模板的支持,允许替换{title}、{content}和{time}等变量。受影响的文件
MeoAsstMac/MeoAsstMacApp.swiftMeoAsstMac/Model/MAAViewModel.swiftMeoAsstMac/Services/Notification/BarkService.swift(新功能)MeoAsstMac/Services/Notification/CustomWebhookService.swift(新功能)MeoAsstMac/Services/Notification/DingTalkBotClient.swift(新功能)MeoAsstMac/Services/Notification/DingTalkService.swift(新功能)MeoAsstMac/Services/Notification/NotificationManager.swift(新功能)MeoAsstMac/Services/Notification/NotificationService.swift(新功能)MeoAsstMac/Services/Notification/QmsgService.swift(新功能)