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