diff --git a/desktop/Ads.Desktop.Smoke/Program.cs b/desktop/Ads.Desktop.Smoke/Program.cs index f0376bd..612bc8c 100644 --- a/desktop/Ads.Desktop.Smoke/Program.cs +++ b/desktop/Ads.Desktop.Smoke/Program.cs @@ -240,8 +240,23 @@ internal static class Program throw new InvalidOperationException(error.Message + "; state=" + vm.ScreenRunning + "; notice=" + vm.Notice + "; logs=" + string.Join(" | ", vm.Logs.TakeLast(25))); } Require(vm.ScreenRunning, "scrcpy process exited unexpectedly"); + if(usb && Environment.GetCommandLineArgs().Contains("--recover")) { + var connection=vm.Connections.Single(c=>c.DeviceId=="home-phone"); + var oldPort=connection.Options.UsbPort; + var textures=vm.Logs.Count(l=>l.Contains("INFO: Texture")); + var field=typeof(DeviceConnection).GetField("client",System.Reflection.BindingFlags.NonPublic|System.Reflection.BindingFlags.Instance)!; + var owned=(System.Diagnostics.Process)field.GetValue(connection)!; + owned.Kill(entireProcessTree:true); + await owned.WaitForExitAsync(); + await UntilAsync(()=>connection.Options.UsbPort!=oldPort && connection.Ready && connection.ScreenRunning && vm.Logs.Count(l=>l.Contains("INFO: Texture"))>textures,"USB remount and video recovery failed: "+connection.Notice); + Console.WriteLine("PASS: client failure automatically remounts USB and restores real scrcpy video"); + } await vm.StopScrcpyCommand.ExecuteAsync(null); Require(!vm.ScreenRunning, "scrcpy did not stop"); + if(usb && Environment.GetCommandLineArgs().Contains("--recover")) { + await Task.Delay(7000); + Require(!vm.ScreenRunning,"Manual stop must cancel automatic video restore"); + } Console.WriteLine("PASS: GUI starts real scrcpy video stream and stops its process"); } await vm.ReconnectCommand.ExecuteAsync(null); diff --git a/desktop/Ads.Desktop.Tests/SelectedPathTests.cs b/desktop/Ads.Desktop.Tests/SelectedPathTests.cs new file mode 100644 index 0000000..4101ac1 --- /dev/null +++ b/desktop/Ads.Desktop.Tests/SelectedPathTests.cs @@ -0,0 +1,21 @@ +using Ads.Desktop; +using Xunit; +namespace Ads.Desktop.Tests; +public class SelectedPathTests +{ + [Fact] + public void SelectedToolIsSavedEvenWhileServerTextIsInvalid() + { + var folder=Path.Combine(Path.GetTempPath(),"ads-path-"+Guid.NewGuid().ToString("N")); + try { + using var vm=new MainViewModel(folder,backgroundMonitoring:false,loadLocalCredentials:false); + vm.Server="incomplete address"; + vm.AdbPath="C:/tools/adb.exe"; + vm.UsbipPath="C:/tools/usbip.exe"; + vm.PersistSelectedPaths(); + var saved=DesktopPaths.LoadSettings(Path.Combine(folder,"settings.json")); + Assert.Equal(vm.AdbPath,saved.Adb); + Assert.Equal(vm.UsbipPath,saved.UsbipPath); + } finally {if(Directory.Exists(folder))Directory.Delete(folder,true);} + } +} diff --git a/desktop/Ads.Desktop/AgentManagementView.axaml b/desktop/Ads.Desktop/AgentManagementView.axaml index 69634ea..31dcf2d 100644 --- a/desktop/Ads.Desktop/AgentManagementView.axaml +++ b/desktop/Ads.Desktop/AgentManagementView.axaml @@ -7,8 +7,8 @@