feat: Claude Code 原生 Windows 通知(C# / .NET 10 + Avalonia 12)

为 Claude Code 提供原生 Windows toast 通知:点击跳回原窗口、切回 Windows
Terminal 标签、跨虚拟桌面、调用方图标、非阻塞投递;NativeAOT 单文件分发。
This commit is contained in:
2026-06-22 18:05:15 +08:00
Unverified
commit 5ce2c8a982
53 changed files with 3889 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
@echo off
setlocal
rem 切到仓库根目录(scripts 的上一级)
cd /d "%~dp0\.."
rem NativeAOT 的原生链接需要 MSVC 工具链,先用 vswhere 找到 VS 并配置环境
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist "%VSWHERE%" (
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSPATH=%%i"
)
if defined VSPATH if exist "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" (
echo === 配置 MSVC 环境: %VSPATH% ===
call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" >nul
)
echo === NativeAOT publish (win-x64) -^> bin\notify.exe ===
dotnet publish Notify -c Release -r win-x64 -p:PublishAot=true -o bin
if errorlevel 1 (
echo.
echo *** 发布失败。若提示找不到 link.exe,请从 "Developer Command Prompt for VS" 运行本脚本 ***
exit /b 1
)
echo.
echo === 完成: %CD%\bin\notify.exe ===
endlocal
+45
View File
@@ -0,0 +1,45 @@
@echo off
rem ============================================================
rem Download URL (notify.exe is fetched from here on first run) -- edit as needed
set "DOWNLOAD_URL=https://git.pchuan.top/cc-tools/notify/releases/download/v1.0.0/notify.exe"
rem ============================================================
setlocal
set "BIN=%~dp0..\bin"
set "EXE=%BIN%\notify.exe"
set "LOCK=%BIN%\notify.download.lock"
rem only bootstrap on first run; the common path runs the exe directly (keeps piped stdin intact)
if not exist "%EXE%" call :bootstrap
if exist "%EXE%" "%EXE%" %*
endlocal
exit /b
:bootstrap
if not exist "%BIN%" mkdir "%BIN%" 2>nul
set "TMP=%BIN%\notify.exe.%RANDOM%.tmp"
rem mkdir is atomic; success = this process downloads, failure = someone else is downloading
mkdir "%LOCK%" 2>nul
if errorlevel 1 goto :waitdl
rem double-check in case it just finished
if exist "%EXE%" ( rmdir "%LOCK%" 2>nul & exit /b )
rem download to temp then atomic rename, so no half-written exe is ever seen
curl -fsSL "%DOWNLOAD_URL%" -o "%TMP%"
if errorlevel 1 ( del "%TMP%" 2>nul & rmdir "%LOCK%" 2>nul & exit /b )
move /y "%TMP%" "%EXE%" >nul
rmdir "%LOCK%" 2>nul
exit /b
:waitdl
rem did not get the lock; wait for the exe to appear (up to ~60s)
set /a _w=0
:waitloop
if exist "%EXE%" exit /b
if %_w% geq 120 (
rem timed out; a killed download may have left a stale lock, clear it for next time
rmdir "%LOCK%" 2>nul
exit /b
)
ping -n 2 127.0.0.1 >nul
set /a _w+=1
goto :waitloop
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# ============================================================
# 下载地址(首次运行从这里拉取 notify.exe)—— 按需修改
DOWNLOAD_URL="https://git.pchuan.top/cc-tools/notify/releases/download/v1.0.0/notify.exe"
# ============================================================
DIR="$(cd "$(dirname "$0")" && pwd)"
BIN="$DIR/../bin"
EXE="$BIN/notify.exe"
LOCK="$BIN/notify.download.lock"
if [ ! -f "$EXE" ]; then
mkdir -p "$BIN" 2>/dev/null
# mkdir 是原子操作,用作锁:成功=本进程负责下载,失败=已有进程在下
if mkdir "$LOCK" 2>/dev/null; then
# 双重检查,避免刚好别人下完
if [ ! -f "$EXE" ]; then
TMP="$BIN/notify.exe.$$.tmp"
if curl -fsSL "$DOWNLOAD_URL" -o "$TMP"; then
mv -f "$TMP" "$EXE" # 原子改名,避免半截 exe
chmod +x "$EXE" 2>/dev/null
else
rm -f "$TMP"
fi
fi
rmdir "$LOCK" 2>/dev/null
else
# 没抢到锁:等 exe 出现(最多约 60 秒)
i=0
while [ ! -f "$EXE" ] && [ "$i" -lt 120 ]; do
sleep 0.5
i=$((i + 1))
done
# 超时仍没下好:可能上次下载被杀留下陈旧锁,清掉让下次重下
[ ! -f "$EXE" ] && rmdir "$LOCK" 2>/dev/null
fi
fi
# 转发全部参数与 stdin 给真正的 exe
[ -f "$EXE" ] && exec "$EXE" "$@"