From 51c4f86918bc7e1804ffe4045e500a31698962a1 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Thu, 12 Nov 2026 15:30:05 +0800 Subject: [PATCH] Sync desktop with public relay and add verified device connection management --- .../Ads.Desktop.Smoke.csproj | 7 + desktop/Ads.Desktop.Smoke/Program.cs | 133 +++++ .../Ads.Desktop.Tests.csproj | 13 + desktop/Ads.Desktop.Tests/ConnectionTests.cs | 115 ++++ desktop/Ads.Desktop/Ads.Desktop.csproj | 1 - desktop/Ads.Desktop/App.axaml.cs | 17 +- desktop/Ads.Desktop/DesktopConfiguration.cs | 128 +++++ desktop/Ads.Desktop/MainViewModel.cs | 539 ++++++++++++++++-- desktop/Ads.Desktop/MainWindow.axaml | 165 ++++-- desktop/Ads.Desktop/MainWindow.axaml.cs | 49 +- desktop/Ads.Desktop/ProcessTools.cs | 63 ++ desktop/Ads.Desktop/RelayApi.cs | 98 ++++ desktop/README.md | 36 +- docs/deployment-ttstd.md | 2 + docs/verification.md | 9 + scripts/build-desktop.ps1 | 25 + scripts/start-desktop.ps1 | 7 + 17 files changed, 1289 insertions(+), 118 deletions(-) create mode 100644 desktop/Ads.Desktop.Smoke/Ads.Desktop.Smoke.csproj create mode 100644 desktop/Ads.Desktop.Smoke/Program.cs create mode 100644 desktop/Ads.Desktop.Tests/Ads.Desktop.Tests.csproj create mode 100644 desktop/Ads.Desktop.Tests/ConnectionTests.cs create mode 100644 desktop/Ads.Desktop/DesktopConfiguration.cs create mode 100644 desktop/Ads.Desktop/ProcessTools.cs create mode 100644 desktop/Ads.Desktop/RelayApi.cs create mode 100644 scripts/build-desktop.ps1 create mode 100644 scripts/start-desktop.ps1 diff --git a/desktop/Ads.Desktop.Smoke/Ads.Desktop.Smoke.csproj b/desktop/Ads.Desktop.Smoke/Ads.Desktop.Smoke.csproj new file mode 100644 index 0000000..6278407 --- /dev/null +++ b/desktop/Ads.Desktop.Smoke/Ads.Desktop.Smoke.csproj @@ -0,0 +1,7 @@ + + Exenet8.0enableenable + + + + + diff --git a/desktop/Ads.Desktop.Smoke/Program.cs b/desktop/Ads.Desktop.Smoke/Program.cs new file mode 100644 index 0000000..343ed7d --- /dev/null +++ b/desktop/Ads.Desktop.Smoke/Program.cs @@ -0,0 +1,133 @@ +using Ads.Desktop; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Headless; +using Avalonia.Threading; + +internal static class Program +{ + [STAThread] + public static int Main(string[] args) + { + AppBuilder.Configure().UseSkia().UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false }).SetupWithoutStarting(); + using var finished = new CancellationTokenSource(); + Exception? failure = null; + Dispatcher.UIThread.Post(async () => + { + try { await RunAsync(args.Contains("--live"), args.Contains("--screen")); } + catch (Exception error) { failure = error; } + finally { finished.Cancel(); } + }); + Dispatcher.UIThread.MainLoop(finished.Token); + if (failure != null) { Console.Error.WriteLine(failure); return 1; } + return 0; + } + + private static void Require(bool condition, string message) + { + if (!condition) throw new InvalidOperationException(message); + } + + private static async Task UntilAsync(Func condition, string message) + { + var deadline = DateTime.UtcNow.AddSeconds(35); + while (!condition()) + { + if (DateTime.UtcNow > deadline) throw new InvalidOperationException(message); + await Task.Delay(150); + } + } + + private static async Task RunAsync(bool live, bool screen) + { + var root = DesktopPaths.ProjectRoot() ?? throw new InvalidOperationException("Project root not found"); + var folder = Path.Combine(root, "work", "desktop-smoke", Guid.NewGuid().ToString("N")); + using var vm = new MainViewModel(folder, backgroundMonitoring: true, loadLocalCredentials: live); + // Avoid collisions with the interactive application or another local ADB device. + var temporary = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, 0); + temporary.Start(); vm.Port = ((System.Net.IPEndPoint)temporary.LocalEndpoint).Port; temporary.Stop(); + var window = new MainWindow { DataContext = vm }; + window.Show(); + await Task.Delay(60); + try + { + Require(window.FindControl("ServerBox")?.Text == RelayOptions.DefaultServer, "Server binding is wrong"); + Require(window.FindControl("OriginBox")?.Text == RelayOptions.DefaultOrigin, "Origin binding is wrong"); + if (!live) + { + Require(window.FindControl