Add opt-in physical USB device enrollment and remembered choices in 0.2.7
This commit is contained in:
1 parent
dc29a20a41
commit
208d37b7d8
20 files changed
+515
-18
No files matched your search
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup><Version>0.2.6</Version><OutputType>WinExe</OutputType><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
|
||||
<PropertyGroup><Version>0.2.7</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>
|
||||
@@ -8,7 +8,7 @@
|
||||
<Grid Grid.Row="1" ColumnDefinitions="300,*">
|
||||
<Border Classes="agentCard" Margin="0,0,14,0"><Grid RowDefinitions="Auto,*"><TextBlock Text="Agent / 被控电脑" FontSize="18" FontWeight="SemiBold"/><ListBox x:Name="AgentList" Grid.Row="1" ItemsSource="{Binding Agents}" SelectedItem="{Binding SelectedAgent}" Margin="0,10,0,0"><ListBox.ItemTemplate><DataTemplate><StackPanel Spacing="5" Margin="4,8"><TextBlock Text="{Binding Id}" FontSize="16"/><TextBlock Text="{Binding Description}" TextWrapping="Wrap" Foreground="{DynamicResource SemiColorText2}"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox></Grid></Border>
|
||||
<ScrollViewer Grid.Column="1"><StackPanel Spacing="14">
|
||||
<Border Classes="agentCard"><StackPanel Spacing="10"><TextBlock Text="{Binding SelectedAgentDetails}" TextWrapping="Wrap" Foreground="{DynamicResource SemiColorPrimary}"/><WrapPanel><Button x:Name="LoadAgentConfigButton" Content="读取配置" Command="{Binding LoadConfigCommand}"/><Button Content="重启 Agent" Command="{Binding RestartAgentCommand}"/></WrapPanel><TextBlock Text="重启由监督进程执行,设备连接会短暂中断。" FontSize="12" Foreground="{DynamicResource SemiColorText2}"/></StackPanel></Border>
|
||||
<Border Classes="agentCard"><StackPanel Spacing="10"><TextBlock Text="{Binding SelectedAgentDetails}" TextWrapping="Wrap" Foreground="{DynamicResource SemiColorPrimary}"/><WrapPanel><Button x:Name="LoadAgentConfigButton" Content="读取配置" Command="{Binding LoadConfigCommand}"/><Button Content="开启 USB 自动注册" Command="{Binding EnableAutoUsbCommand}"/><Button Content="关闭 USB 自动注册" Command="{Binding DisableAutoUsbCommand}"/><Button Content="取消所选发现设备的忽略" Command="{Binding UnignoreUsbCommand}"/><Button Content="重启 Agent" Command="{Binding RestartAgentCommand}"/></WrapPanel><TextBlock Text="USB 自动注册默认关闭,仅支持 Windows/Linux 真实 USB。删除后记为忽略,停用不会自动恢复;当前开关和忽略列表可读取配置查看。重启会短暂中断设备连接。" FontSize="12" Foreground="{DynamicResource SemiColorText2}"/></StackPanel></Border>
|
||||
<Border Classes="agentCard"><StackPanel Spacing="8">
|
||||
<Button Content="发现 ADB 设备" Command="{Binding DiscoverDevicesCommand}" HorizontalAlignment="Left"/>
|
||||
<ListBox ItemsSource="{Binding DiscoveredDevices}" SelectedItem="{Binding SelectedDiscoveredDevice}" MaxHeight="160"><ListBox.ItemTemplate><DataTemplate><TextBlock Text="{Binding Description}" TextWrapping="Wrap"/></DataTemplate></ListBox.ItemTemplate></ListBox>
|
||||
|
||||
@@ -179,6 +179,22 @@ public partial class AgentManagementViewModel : ObservableObject, IDisposable
|
||||
[RelayCommand(CanExecute=nameof(CanManage))]private Task LoadConfigAsync()=>Guard(async()=>{
|
||||
var value=await CallAsync(new{op="config_get"});ConfigJson=JsonSerializer.Serialize(value,new JsonSerializerOptions{WriteIndented=true});Notice="已读取配置,凭据不在配置中。";
|
||||
});
|
||||
private Task UpdateUsbPolicy(bool? enabled)=>Guard(async()=>{
|
||||
var value=await CallAsync(new{op="config_get"});
|
||||
var config=System.Text.Json.Nodes.JsonNode.Parse(value.GetRawText())!.AsObject();
|
||||
var expected_config=config.DeepClone();
|
||||
if(enabled.HasValue)config["auto_register_usb"]=enabled.Value;
|
||||
else {
|
||||
var serial=SelectedDiscoveredDevice?.Serial ?? throw new InvalidOperationException("请先发现并选择需要取消忽略的设备。");
|
||||
var ignored=config["ignored_usb_serials"]?.AsArray() ?? new System.Text.Json.Nodes.JsonArray();
|
||||
config["ignored_usb_serials"]=new System.Text.Json.Nodes.JsonArray(ignored.Where(n=>n?.GetValue<string>()!=serial).Select(n=>n?.DeepClone()).ToArray());
|
||||
}
|
||||
await CallAsync(new{op="config_set",config,expected_config});ConfigJson=config.ToJsonString(new JsonSerializerOptions{WriteIndented=true});
|
||||
await RefreshCoreAsync();Notice=enabled.HasValue?(enabled.Value?"已开启真实 USB 自动注册。":"已关闭自动注册,已有设备保留。 "):"已取消该设备的忽略记录;开启自动注册后将重新检查。";
|
||||
});
|
||||
[RelayCommand(CanExecute=nameof(CanManage))]private Task EnableAutoUsbAsync()=>UpdateUsbPolicy(true);
|
||||
[RelayCommand(CanExecute=nameof(CanManage))]private Task DisableAutoUsbAsync()=>UpdateUsbPolicy(false);
|
||||
[RelayCommand(CanExecute=nameof(CanManage))]private Task UnignoreUsbAsync()=>UpdateUsbPolicy(null);
|
||||
[RelayCommand(CanExecute=nameof(CanManage))]private Task SaveConfigAsync()=>Guard(async()=>{
|
||||
using var doc=JsonDocument.Parse(ConfigJson);await CallAsync(new{op="config_set",config=doc.RootElement});await RefreshCoreAsync();Notice="配置已持久化并应用。受影响设备将重建连接。";
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user