feat: 打通 hook CLI 与命名管道链路(P0)
- 子命令 save/notify/input/cleanup:纯互操作 IPC,不加载 Avalonia
- 命名管道:瘦客户端投递请求,Host 未运行时自动拉起并重试
- 每会话状态文件 %TEMP%\claude-notify-{id}.json,保存前台窗口与 prompt
- Host 单例互斥量 + 管道监听,收到请求切回 UI 线程弹窗
- stdin 改为 UTF-8 原始字节读取,修复中文乱码与读不到的问题
- 符合 Claude Code 插件规范的 .claude-plugin 与 hooks 结构
This commit is contained in:
+33
-1
@@ -1,11 +1,17 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Notify.Cli;
|
||||
using Notify.Ipc;
|
||||
|
||||
namespace Notify;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
// 保活期间持有,确保 Host 单例
|
||||
private static Mutex? _hostMutex;
|
||||
|
||||
// Avalonia configuration, don't remove; also used by the visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp() =>
|
||||
AppBuilder.Configure<App>()
|
||||
@@ -14,8 +20,34 @@ internal static class Program
|
||||
.LogToTrace();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args) =>
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var mode = args.Length > 0 ? args[0].ToLowerInvariant() : "host";
|
||||
|
||||
// 钩子子命令:纯互操作 / IPC,不加载 Avalonia
|
||||
return mode switch
|
||||
{
|
||||
"save" => CliRunner.Save(),
|
||||
"notify" => CliRunner.Notify(),
|
||||
"input" => CliRunner.Input(),
|
||||
"cleanup" => CliRunner.Cleanup(),
|
||||
_ => RunHost(args),
|
||||
};
|
||||
}
|
||||
|
||||
// 常驻 Host:加载 Avalonia,无主窗口保活,监听命名管道
|
||||
private static int RunHost(string[] args)
|
||||
{
|
||||
_hostMutex = new Mutex(true, IpcConstants.HostMutexName, out var created);
|
||||
if (!created)
|
||||
{
|
||||
// 已有 Host 在跑,本进程退出
|
||||
return 0;
|
||||
}
|
||||
|
||||
BuildAvaloniaApp()
|
||||
// OnExplicitShutdown = 持续保活:没有主窗口也不会退出,只有显式 Shutdown 才结束
|
||||
.StartWithClassicDesktopLifetime(args, ShutdownMode.OnExplicitShutdown);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user