Skip to content

chofuhoyu/notify-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

notify-server

在 Windows 本机运行的 HTTP 通知服务,通过原生 Windows Toast API 发送桌面通知。

背景

WSL2 的 binfmt_misc interop 在某些版本中存在 bug,导致 WSL 侧无法直接调用 Windows 原生通知。网络栈的稳定性通常优于 interop,因此本工具选择通过 HTTP 请求来转发通知:WSL2 内通过 curl 向 Windows 本机发送请求,由 notify-server 使用 Windows Toast API 弹出通知。

依赖

无外部运行时依赖。所有功能通过 winrt-toast-reborn 静态链接实现。

安装

cargo install notify-server

用法

# 默认监听 127.0.0.1:6960
notify-server

# 自定义地址和图标
notify-server -l 127.0.0.1:8080 -p "C:\path\to\icon.png"

# 查看帮助
notify-server --help

由于本项目的设计初衷是与 Claude Code 集成,默认图标会指向 %USERPROFILE%\.dotfiles\icon\claude_code.png。可通过 -p 参数指定其他图标。

启动后,通过 HTTP POST 发送通知:

curl -s -X POST http://localhost:6960/notify \
  -H "Content-Type: application/json" \
  -d '{"title":"标题","message":"通知内容"}'

API

POST /notify,Content-Type: application/json

请求体字段:

字段 类型 必填 说明
title string 通知标题
message string 通知正文

请求体中允许携带额外字段(如 sound),会被忽略。

与 Claude Code 集成

~/.claude/settings.json 中配置 hooks:

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash $HOME/.claude/notify.sh 'Claude Code' 'Claude Code 已完成响应,等待你的下一条 prompt' 'stop'"
          }
        ]
      }
    ]
  }
}

notify.sh 示例见 examples/notify.sh

License

MIT

About

A small Rust HTTP server for Windows notification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages