Monitor ADB device presence and withdraw stale registrations in 0.2.6

This commit is contained in:
tongtong committed 2026-11-13 21:55:45 +08:00
1 parent 03e729a60b
commit dc29a20a41
17 files changed
+488 -23

No files matched your search

@@ -0,0 +1,17 @@
using Ads.Desktop;
using Xunit;
namespace Ads.Desktop.Tests;
public class DevicePresenceTests {
[Fact] public void MissingRemoteDeviceDoesNotKeepOldReadyDescription() {
var item=new DeviceItem("phone",true,true,Online:false,LocalSummary:"ADB 就绪");
Assert.Contains("离线",item.Description);Assert.DoesNotContain("就绪",item.Description);
}
[Fact] public void AgentDeviceShowsUnavailableReason() {
var item=new ManagedDevice("phone",null,"USB-A",null,5555,true,false,"ADB 未发现该设备");
Assert.Contains("ADB 未发现",item.Description);Assert.DoesNotContain("已注册",item.Description);
}
[Fact] public void DisabledDeviceKeepsItsExplicitState() {
var item=new ManagedDevice("phone",null,"USB-A",null,5555,false,false,"ADB 未发现该设备");
Assert.Contains("已停用",item.Description);
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><Version>0.2.5</Version><OutputType>WinExe</OutputType><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<PropertyGroup><Version>0.2.6</Version><OutputType>WinExe</OutputType><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<ItemGroup><PackageReference Include="Avalonia.Desktop" Version="11.3.8"/><PackageReference Include="Semi.Avalonia" Version="11.3.7.3"/><PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0"/></ItemGroup>
<ItemGroup><AvaloniaResource Include="Assets/**"/></ItemGroup></Project>
+1 -1
View File
@@ -12,7 +12,7 @@ public sealed record ManagedDevice(
[property:JsonPropertyName("device_port")] int DevicePort, bool Enabled, bool Connected,
[property:JsonPropertyName("last_error")] string? LastError)
{
public string Description => $"{Id} · {(Enabled ? Connected ? LastError==null ? "已注册" : "转发异常" : "等待注册" : "已停用")} · {Target ?? AdbSerial}";
public string Description => $"{Id} · {(Enabled ? Connected ? LastError==null ? "已注册" : "转发异常:"+LastError : LastError==null ? "等待注册" : "未就绪:"+LastError : "已停用")} · {Target ?? AdbSerial}";
}
public sealed record ManagedStatus(string Id, string Name, string Hostname, string Os, string Arch, string Version, int Pid,
[property:JsonPropertyName("uptime_seconds")] long UptimeSeconds, bool Supervised, long Revision, string Instance, ManagedDevice[] Devices);
+1 -1
View File
@@ -11,7 +11,7 @@ namespace Ads.Desktop;
public sealed record DeviceItem(string Id, bool Busy, bool IsLocal, bool Online = true, string LocalSummary = "", string ComputerName="", string AgentId="")
{
public string ComputerLabel => "电脑:"+(ComputerName.Length==0?"未上报电脑名":ComputerName)+(AgentId.Length==0?"":" · "+AgentId);
public string Description => IsLocal ? "本机 · " + LocalSummary : !Online ? "远程暂时离线" : Busy ? "在线 · 其他客户端使用中" : "在线 · 可连接";
public string Description => !Online ? (IsLocal ? "远端离线 · 本机通道等待恢复" : "远程暂时离线") : IsLocal ? "本机 · " + LocalSummary : Busy ? "在线 · 其他客户端使用中" : "在线 · 可连接";
}
public partial class MainViewModel : ObservableObject, IDisposable