🔔 跨平台桌面通知系统,支持 Windows、macOS 和 Linux
Trae Notification System 是一个轻量级的跨平台桌面通知解决方案,专为开发者和自动化工具设计。它提供了简单易用的 API,支持在任务完成、构建成功或其他重要事件发生时发送系统通知。
- 🌍 跨平台支持:Windows、macOS、Linux 三大平台
- 🔧 多种通知方式:PowerShell BurntToast、原生通知、osascript、notify-send
- 🛡️ 智能降级:自动选择最佳可用的通知方法
- 📝 自定义消息:支持自定义标题和内容
- ⚡ 轻量级:无重依赖,开箱即用
- 🎯 易于集成:可轻松集成到现有项目和工作流中
# 基础 Python 环境(Python 3.6+)
python --version
# Windows 用户(可选,用于更好的通知体验)
Install-Module BurntToast
# 或安装 Python 包
pip install win10toast# 默认通知
python notification_script.py
# 自定义标题和消息
python notification_script.py "构建完成" "项目已成功构建并部署"
# 使用简化版本
python simple_notify.py# 默认通知
notify.bat
# 自定义通知
notify.bat "任务完成" "所有测试已通过"from notification_script import show_notification
# 发送通知
show_notification(
title="部署成功",
message="应用已成功部署到生产环境",
duration=5000
)| 文件 | 描述 |
|---|---|
notification_script.py |
完整版通知脚本,支持所有平台和功能 |
simple_notify.py |
简化版通知脚本,模拟 plyer.notification.notify |
notify.bat |
Windows 批处理脚本,便于命令行调用 |
requirements.txt |
Python 依赖包列表 |
examples/ |
使用示例和集成案例 |
在 .vscode/tasks.json 中添加:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Notification",
"type": "shell",
"command": "npm run build && python notification_script.py 'Build Complete' 'Project built successfully'",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always"
}
}
]
}在 package.json 中添加:
{
"scripts": {
"build:notify": "npm run build && python ../notification_script.py 'Build Complete' 'Extension built successfully'",
"test:notify": "npm test && python ../notification_script.py 'Tests Complete' 'All tests passed'"
}
}在 .git/hooks/post-commit 中:
#!/bin/sh
python notification_script.py "Git Commit" "Changes committed successfully"# GitHub Actions 示例
- name: Send notification
run: |
python notification_script.py "Deployment Complete" "Application deployed to production"要让 AI 在每次回答结束后自动调用通知脚本,您需要在 Trae IDE 中配置自定义指令:
- 在 Trae IDE 中创建
project_rules.md文件- 在项目根目录创建或编辑
project_rules.md文件 - 添加以下自定义指令:
- 在项目根目录创建或编辑
# 项目自定义规则
## 任务完成通知
- "Always run notify_tool after task completion."(任务完成后总是运行通知工具)
- "Break down complex problems into smaller components."(分解复杂问题)
- "Use try-catch for error handling in code."(代码中用 try-catch)- 通知脚本集成规则
在
project_rules.md中添加:
## 自动通知规则
每当 AI 完成任务后,自动执行:
`python notification_script.py "任务完成" "具体完成的任务描述"`- 保存并生效
- 保存
project_rules.md文件 - Trae IDE 会自动读取这些规则
- AI 将在每次回答结束时遵循这些指令
- 保存
- ✅ PowerShell BurntToast 模块
- ✅ win10toast Python 包
- ✅ 原生 msg 命令
- ✅ 系统托盘通知
- ✅ osascript 通知
- ✅ 原生通知中心集成
- ✅ 自定义图标支持
- ✅ notify-send 命令
- ✅ libnotify 支持
- ✅ 桌面环境兼容
# 启用/禁用通知
export NOTIFY_ENABLED=true
# 默认通知标题前缀
export NOTIFY_TITLE_PREFIX="MyApp"
# 通知显示时长(毫秒)
export NOTIFY_DURATION=5000创建 .notify_config.json:
{
"enabled": true,
"default_title": "Trae通知",
"default_duration": 5000,
"platform_preferences": {
"windows": "burnttoast",
"macos": "osascript",
"linux": "notify-send"
}
}- 在
notification_script.py中添加新的平台检测 - 实现对应的通知函数
- 添加错误处理和降级机制
- 更新文档和测试
# 测试所有平台
python test_notifications.py
# 测试特定平台
python test_notifications.py --platform windows- ✨ 初始版本发布
- 🌍 支持 Windows、macOS、Linux
- 🔧 多种通知方式支持
- 📚 完整文档和示例
- Fork 本项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情
- BurntToast - Windows PowerShell 通知模块
- win10toast - Windows Python 通知库
- plyer - 跨平台 API 设计灵感
如果您遇到问题或有建议,请:
- 📋 提交 Issue
- 💬 参与讨论
- 📧 发送邮件至:moyaor@sina.com
⭐ 如果这个项目对您有帮助,请给我们一个星标!