13fe87da99
- WindowActivator:ALT 模拟 + AttachThreadInput + SetForegroundWindow 组合技抢前台 - save 抓的前台句柄经 PipeMessage/ToastRequest 一路带到 toast - 点击 toast 主体激活目标窗口后再关闭 - Win32 互操作用 LibraryImport(AOT 友好) - 新增 acttest 自测子命令
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
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(),
|
|
"acttest" => CliRunner.ActTest(args),
|
|
_ => 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;
|
|
}
|
|
}
|