feat: Claude Code 原生 Windows 通知(C# / .NET 10 + Avalonia 12)
为 Claude Code 提供原生 Windows toast 通知:点击跳回原窗口、切回 Windows Terminal 标签、跨虚拟桌面、调用方图标、非阻塞投递;NativeAOT 单文件分发。
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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>()
|
||||
.UsePlatformDetect()
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
|
||||
[STAThread]
|
||||
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