feat: add Flutter USB mirroring and single-instance desktop clients
This commit is contained in:
1 parent
3a7bb071f0
commit
a339465392
30 files changed
+1688
-104
No files matched your search
@@ -23,6 +23,7 @@ public partial class App : Application
|
||||
desktop.MainWindow = window;
|
||||
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
||||
void Show() { window.Show(); window.WindowState = WindowState.Normal; window.Activate(); }
|
||||
Program.Instance?.Listen(() => Avalonia.Threading.Dispatcher.UIThread.Post(Show));
|
||||
async Task QuitAsync()
|
||||
{
|
||||
if (quitting) return;
|
||||
@@ -59,4 +60,3 @@ public partial class App : Application
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ads.Desktop;
|
||||
|
||||
/// <summary>Shares the Windows desktop UI lease with Flutter, including tray mode.</summary>
|
||||
internal sealed class DesktopInstance : IDisposable
|
||||
{
|
||||
private readonly Mutex mutex;
|
||||
private readonly EventWaitHandle activation;
|
||||
private RegisteredWaitHandle? registration;
|
||||
public bool Primary { get; }
|
||||
|
||||
public DesktopInstance()
|
||||
{
|
||||
activation = new EventWaitHandle(false, EventResetMode.AutoReset, @"Local\TTSTD.ADS.Desktop.Activate");
|
||||
mutex = new Mutex(true, @"Local\TTSTD.ADS.Desktop.Instance", out var primary);
|
||||
Primary = primary;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
AllowSetForegroundWindow(uint.MaxValue);
|
||||
activation.Set();
|
||||
}
|
||||
|
||||
public void Listen(Action show) =>
|
||||
registration = ThreadPool.RegisterWaitForSingleObject(activation, (_, _) => show(), null, Timeout.Infinite, false);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
registration?.Unregister(null);
|
||||
if (Primary) mutex.ReleaseMutex();
|
||||
mutex.Dispose();
|
||||
activation.Dispose();
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool AllowSetForegroundWindow(uint processId);
|
||||
}
|
||||
@@ -2,6 +2,16 @@ using Avalonia;
|
||||
namespace Ads.Desktop;
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread] public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
public static DesktopInstance? Instance { get; private set; }
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (!OperatingSystem.IsWindows()) { BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); return; }
|
||||
using var instance = new DesktopInstance();
|
||||
Instance = instance;
|
||||
if (!instance.Primary) { instance.Activate(); return; }
|
||||
try { BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); }
|
||||
finally { Instance = null; }
|
||||
}
|
||||
public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>().UsePlatformDetect().LogToTrace();
|
||||
}
|
||||
@@ -76,3 +76,7 @@ ADB、USB/IP 和 scrcpy 转发端口分别自动分配,避开其他连接和
|
||||
## Agent 管理
|
||||
|
||||
工作台新增 Agent 管理页,与 Flutter 共用控制中心 v3 接口。支持多 Agent/多手机、本机私有 IPC、配置与日志、受监督重启;`--agent-tray` 可单独打开本机 Agent 管理窗口。发行包同时包含 adsctl 和 ads-agent,后台运行不依赖 GUI。完整安装及 CLI 示例见 [Agent 管理](../docs/agent-management.md)。
|
||||
|
||||
## Windows 单实例
|
||||
|
||||
Windows 桌面入口与 Flutter 共用同一会话级单实例锁(包括 --agent-tray 入口和不同安装路径)。重复启动会唤起正在运行的桌面窗口并退出新进程,避免重复托盘及重复设备管理。后台 Agent 和设备连接进程不受该 UI 锁限制。DesktopInstance.cs 使用 Windows 命名事件通知,由 Avalonia UI 线程恢复窗口。非 Windows 暂保留原启动行为。
|
||||
Reference in new issue
Block a user