Skip to content

yaolinhui/trae-notification-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trae Notification System

🔔 跨平台桌面通知系统,支持 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

基本使用

1. Python 脚本方式

# 默认通知
python notification_script.py

# 自定义标题和消息
python notification_script.py "构建完成" "项目已成功构建并部署"

# 使用简化版本
python simple_notify.py

2. Windows 批处理方式

# 默认通知
notify.bat

# 自定义通知
notify.bat "任务完成" "所有测试已通过"

3. 编程方式集成

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/ 使用示例和集成案例

🔧 集成示例

VS Code 任务集成

.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"
      }
    }
  ]
}

NPM Scripts 集成

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 集成

.git/hooks/post-commit 中:

#!/bin/sh
python notification_script.py "Git Commit" "Changes committed successfully"

CI/CD 集成

# GitHub Actions 示例
- name: Send notification
  run: |
    python notification_script.py "Deployment Complete" "Application deployed to production"

⚙️ Trae IDE 自动化配置

配置自定义指令实现自动通知

要让 AI 在每次回答结束后自动调用通知脚本,您需要在 Trae IDE 中配置自定义指令:

  1. 在 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)
  1. 通知脚本集成规则project_rules.md 中添加:
## 自动通知规则
每当 AI 完成任务后,自动执行:
`python notification_script.py "任务完成" "具体完成的任务描述"`
  1. 保存并生效
    • 保存 project_rules.md 文件
    • Trae IDE 会自动读取这些规则
    • AI 将在每次回答结束时遵循这些指令

🌍 平台支持详情

Windows

  • ✅ PowerShell BurntToast 模块
  • ✅ win10toast Python 包
  • ✅ 原生 msg 命令
  • ✅ 系统托盘通知

macOS

  • ✅ osascript 通知
  • ✅ 原生通知中心集成
  • ✅ 自定义图标支持

Linux

  • ✅ 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"
  }
}

🛠️ 开发指南

添加新的通知方式

  1. notification_script.py 中添加新的平台检测
  2. 实现对应的通知函数
  3. 添加错误处理和降级机制
  4. 更新文档和测试

测试

# 测试所有平台
python test_notifications.py

# 测试特定平台
python test_notifications.py --platform windows

📝 更新日志

v1.0.0 (2024-01-20)

  • ✨ 初始版本发布
  • 🌍 支持 Windows、macOS、Linux
  • 🔧 多种通知方式支持
  • 📚 完整文档和示例

🤝 贡献指南

  1. Fork 本项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情

🙏 致谢

📞 支持

如果您遇到问题或有建议,请:


⭐ 如果这个项目对您有帮助,请给我们一个星标!

About

🤖 Trae AI 任务完成通知器 - 当 AI 完成编程任务时发送智能桌面提醒,支持跨平台

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors