feat: improve desktop path selection and USB connection recovery
This commit is contained in:
1 parent
5aa575f182
commit
6490665af8
28 files changed
+846
-51
No files matched your search
@@ -7,8 +7,8 @@
|
||||
<Grid RowDefinitions="Auto,*,Auto" Margin="0,14,0,0">
|
||||
<StackPanel>
|
||||
<WrapPanel><CheckBox x:Name="LocalAgentMode" Content="管理本机 Agent" IsChecked="{Binding LocalMode}" IsEnabled="{Binding !IsBusy}" Margin="0,0,20,8"/><CheckBox Content="自动刷新" IsChecked="{Binding AutoRefresh}"/><Button x:Name="RefreshAgentsButton" Content="刷新 Agent" Command="{Binding RefreshAgentsCommand}" IsEnabled="{Binding !IsBusy}" Margin="20,0,0,10"/></WrapPanel>
|
||||
<StackPanel IsVisible="{Binding !LocalMode}"><TextBlock Text="远程管理使用工作台的控制中心地址,需要独立的管理员凭据。" TextWrapping="Wrap"/><Grid ColumnDefinitions="*,Auto"><TextBox x:Name="AdminTokenBox" Text="{Binding AdminToken}" PasswordChar="●" Watermark="ADS_ADMIN_TOKEN"/><Button Grid.Column="1" Content="导入 admin.env" Click="ImportAdminClick" Margin="12,4,0,10"/></Grid></StackPanel>
|
||||
<StackPanel IsVisible="{Binding LocalMode}"><TextBlock Text="本机配置路径"/><TextBox Text="{Binding ConfigPath}"/><WrapPanel><Button Content="启动后台 Agent" Command="{Binding StartLocalCommand}"/><Button Content="安装开机服务" Command="{Binding InstallServiceCommand}"/></WrapPanel></StackPanel>
|
||||
<StackPanel IsVisible="{Binding !LocalMode}"><TextBlock Text="远程管理使用工作台的控制中心地址,需要独立的管理员凭据。" TextWrapping="Wrap"/><TextBlock Text="{Binding AdminPath}" TextWrapping="Wrap"/><Grid ColumnDefinitions="*,Auto"><TextBox x:Name="AdminTokenBox" Text="{Binding AdminToken}" PasswordChar="●" Watermark="ADS_ADMIN_TOKEN"/><Button Grid.Column="1" Content="导入 admin.env" Click="ImportAdminClick" Margin="12,4,0,10"/></Grid></StackPanel>
|
||||
<StackPanel IsVisible="{Binding LocalMode}"><TextBlock Text="本机配置路径"/><Grid ColumnDefinitions="*,Auto"><TextBox Text="{Binding ConfigPath}"/><Button Grid.Column="1" Content="选择" Click="ChooseConfigClick"/></Grid><WrapPanel><Button Content="启动后台 Agent" Command="{Binding StartLocalCommand}"/><Button Content="安装开机服务" Command="{Binding InstallServiceCommand}"/></WrapPanel></StackPanel>
|
||||
</StackPanel>
|
||||
<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="#A8B7CC"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox></Grid></Border>
|
||||
@@ -25,7 +25,7 @@
|
||||
<Button x:Name="AddManagedDeviceButton" Content="添加手机" Command="{Binding AddDeviceCommand}" HorizontalAlignment="Left"/>
|
||||
</StackPanel></Border>
|
||||
<Border Classes="agentCard"><StackPanel Spacing="8"><TextBlock Text="Agent 配置" FontSize="18" FontWeight="SemiBold"/><TextBlock Text="修改设备或地址会重建受影响的连接;Agent ID 保持固定。" Foreground="#A8B7CC" TextWrapping="Wrap"/><TextBox x:Name="AgentConfigBox" Text="{Binding ConfigJson}" AcceptsReturn="True" FontFamily="Cascadia Mono,Consolas" FontSize="12" MinHeight="200" MaxHeight="380" ScrollViewer.VerticalScrollBarVisibility="Auto"/><Button Content="保存并应用配置" Command="{Binding SaveConfigCommand}" HorizontalAlignment="Left"/>
|
||||
<StackPanel IsVisible="{Binding LocalMode}"><TextBlock Text="首次设置:填写上方配置及设备端凭据后初始化,再启动后台 Agent。" TextWrapping="Wrap"/><TextBox Text="{Binding EnrollmentToken}" PasswordChar="●" Watermark="ADS_AGENT_TOKEN"/><WrapPanel><Button Content="导入 agent.env" Click="ImportEnrollmentClick"/><Button Content="初始化本机配置" Command="{Binding InitializeLocalCommand}"/></WrapPanel></StackPanel>
|
||||
<StackPanel IsVisible="{Binding LocalMode}"><TextBlock Text="首次设置:填写上方配置及设备端凭据后初始化,再启动后台 Agent。" TextWrapping="Wrap"/><TextBlock Text="{Binding EnrollmentPath}" TextWrapping="Wrap"/><TextBox Text="{Binding EnrollmentToken}" PasswordChar="●" Watermark="ADS_AGENT_TOKEN"/><WrapPanel><Button Content="导入 agent.env" Click="ImportEnrollmentClick"/><Button Content="初始化本机配置" Command="{Binding InitializeLocalCommand}"/></WrapPanel></StackPanel>
|
||||
</StackPanel></Border>
|
||||
<Border Classes="agentCard"><StackPanel Spacing="8"><WrapPanel><Button Content="读取日志" Command="{Binding ReadLogsCommand}"/><CheckBox Content="持续跟随日志" IsChecked="{Binding FollowLogs}"/></WrapPanel><TextBox x:Name="AgentLogsBox" Text="{Binding RemoteLogText}" IsReadOnly="True" AcceptsReturn="True" FontFamily="Cascadia Mono,Consolas" FontSize="12" Height="200" ScrollViewer.VerticalScrollBarVisibility="Auto"/></StackPanel></Border>
|
||||
</StackPanel></ScrollViewer>
|
||||
|
||||
@@ -10,8 +10,19 @@ public partial class AgentManagementView : UserControl
|
||||
if(DataContext is not AgentManagementViewModel vm)return;
|
||||
try {
|
||||
var top=TopLevel.GetTopLevel(this);if(top==null)return;
|
||||
var files=await top.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions{Title=enrollment?"选择 agent.env":"选择 admin.env",AllowMultiple=false,FileTypeFilter=[new FilePickerFileType("环境配置"){Patterns=["*.env"]}]});
|
||||
if(files.FirstOrDefault()?.TryGetLocalPath() is {} path){if(enrollment)vm.ImportEnrollment(path);else vm.ImportAdmin(path);}
|
||||
var directory=Path.GetDirectoryName(vm.RememberedPath(enrollment?"enrollment":"admin"));
|
||||
var location=directory is not null && Directory.Exists(directory) ? await top.StorageProvider.TryGetFolderFromPathAsync(new Uri(Path.GetFullPath(directory))) : null;
|
||||
var files=await top.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions{SuggestedStartLocation=location,Title=enrollment?"选择 agent.env":"选择 admin.env",AllowMultiple=false,FileTypeFilter=[new FilePickerFileType("环境配置"){Patterns=["*.env"]}]});
|
||||
if(files.FirstOrDefault()?.TryGetLocalPath() is {} path){vm.RememberPath(enrollment?"enrollment":"admin",path);if(enrollment)vm.ImportEnrollment(path);else vm.ImportAdmin(path);}
|
||||
}catch(Exception error){vm.Notice=error.Message;}
|
||||
}
|
||||
private async void ChooseConfigClick(object? sender,RoutedEventArgs e)
|
||||
{
|
||||
if(DataContext is not AgentManagementViewModel vm)return;
|
||||
try {
|
||||
var top=TopLevel.GetTopLevel(this);if(top==null)return;
|
||||
var files=await top.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions {Title="选择 Agent 配置",AllowMultiple=false,FileTypeFilter=[new FilePickerFileType("JSON"){Patterns=["*.json"]},FilePickerFileTypes.All]});
|
||||
if(files.FirstOrDefault()?.TryGetLocalPath() is {} path){vm.ConfigPath=path;vm.RememberPath("config",path);}
|
||||
}catch(Exception error){vm.Notice=error.Message;}
|
||||
}
|
||||
private async void ImportAdminClick(object? sender,RoutedEventArgs e)=>await Import(false);
|
||||
|
||||
@@ -56,6 +56,11 @@ public partial class AgentManagementViewModel : ObservableObject, IDisposable
|
||||
public AgentManagementViewModel(Func<(string,string)> server, Action<string>? logger=null, bool background=true, bool credentials=true)
|
||||
{
|
||||
this.server=server; log=logger ?? (_=>{});
|
||||
try {
|
||||
var paths=Path.Combine(DesktopPaths.SettingsFolder,"agent-ui-paths.json");
|
||||
if(File.Exists(paths))foreach(var entry in JsonSerializer.Deserialize<Dictionary<string,string>>(File.ReadAllText(paths)) ?? new())chosenPaths[entry.Key]=entry.Value;
|
||||
if(chosenPaths.TryGetValue("config",out var config))ConfigPath=config;
|
||||
}catch(Exception e){Notice="读取文件位置失败:"+e.Message;}
|
||||
var (initialServer,initialOrigin)=server();
|
||||
ConfigJson=JsonSerializer.Serialize(new {version=1,id="local-pc",name=Environment.MachineName,server=initialServer,connect_address=string.IsNullOrWhiteSpace(initialOrigin)?null:initialOrigin,adb_server="127.0.0.1:5037",devices=Array.Empty<object>()}, new JsonSerializerOptions{WriteIndented=true});
|
||||
if(credentials) {
|
||||
@@ -68,6 +73,16 @@ public partial class AgentManagementViewModel : ObservableObject, IDisposable
|
||||
public static string DefaultConfig() => OperatingSystem.IsWindows()
|
||||
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"AndroidDeviceStreaming","agent","agent.json")
|
||||
: Path.Combine(Environment.GetEnvironmentVariable("XDG_CONFIG_HOME") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),".config"),"ads","agent.json");
|
||||
private readonly Dictionary<string,string> chosenPaths = new();
|
||||
public string AdminPath=>RememberedPath("admin");
|
||||
public string EnrollmentPath=>RememberedPath("enrollment");
|
||||
public string RememberedPath(string key) => chosenPaths.GetValueOrDefault(key,"");
|
||||
public void RememberPath(string key,string path) {
|
||||
chosenPaths[key]=path;OnPropertyChanged(nameof(AdminPath));OnPropertyChanged(nameof(EnrollmentPath));
|
||||
Directory.CreateDirectory(DesktopPaths.SettingsFolder);
|
||||
var file=Path.Combine(DesktopPaths.SettingsFolder,"agent-ui-paths.json");
|
||||
File.WriteAllText(file,JsonSerializer.Serialize(chosenPaths));
|
||||
}
|
||||
public void StartMonitoring()=>timer.Start();
|
||||
private string Redact(string value) { foreach(var secret in secrets) value=value.Replace(secret,"[REDACTED]",StringComparison.Ordinal);return value; }
|
||||
partial void OnAdminTokenChanged(string value){if(value.Length>0)secrets.Add(value);}
|
||||
@@ -98,14 +113,14 @@ public partial class AgentManagementViewModel : ObservableObject, IDisposable
|
||||
if(new FileInfo(path).Length>65536)throw new InvalidOperationException("凭据文件过大。");
|
||||
var token=File.ReadLines(path).Select(l=>l.Split('=',2)).FirstOrDefault(p=>p.Length==2&&p[0].Trim()=="ADS_ADMIN_TOKEN")?.ElementAt(1).Trim();
|
||||
if(string.IsNullOrEmpty(token)||token.Length<32||token.Contains('\r')||token.Contains('\n'))throw new InvalidOperationException("文件中没有有效的 ADS_ADMIN_TOKEN。");
|
||||
AdminToken=token;Notice="管理员凭据已加载,内容仅保存在内存中。";
|
||||
RememberPath("admin",path);AdminToken=token;Notice="管理员凭据已加载,内容仅保存在内存中。";
|
||||
}
|
||||
public void ImportEnrollment(string path)
|
||||
{
|
||||
if(new FileInfo(path).Length>65536)throw new InvalidOperationException("凭据文件过大。");
|
||||
var value=File.ReadLines(path).FirstOrDefault(l=>l.StartsWith("ADS_AGENT_TOKEN=",StringComparison.Ordinal))?[16..].Trim();
|
||||
if(string.IsNullOrEmpty(value)||value.Length<32)throw new InvalidOperationException("文件中没有有效的 ADS_AGENT_TOKEN。");
|
||||
EnrollmentToken=value;Notice="设备端凭据已加载,仅供本机初始化使用。";
|
||||
RememberPath("enrollment",path);EnrollmentToken=value;Notice="设备端凭据已加载,仅供本机初始化使用。";
|
||||
}
|
||||
private RelayOptions Options(){var(s,o)=server();return RelayOptions.Parse(s,o,AdminToken);}
|
||||
private async Task Guard(Func<Task> action)
|
||||
|
||||
@@ -12,7 +12,7 @@ public sealed record ConnectionOptions(RelayOptions Relay, string Client, string
|
||||
public partial class DeviceConnection : ObservableObject, IDisposable
|
||||
{
|
||||
public string DeviceId { get; }
|
||||
public ConnectionOptions Options { get; }
|
||||
public ConnectionOptions Options { get; private set; }
|
||||
public string Mode => Options.UsbMode ? "USB ADB" : "网络 ADB";
|
||||
public string PortSummary => $"隧道 {Options.Port}" + (Options.UsbPort is { } u ? $" · USB/IP {u}" : "") + (ScreenPort is { } p ? $" · 投屏 {p}" : "");
|
||||
public string RawEndpoint => $"127.0.0.1:{Options.Port}";
|
||||
@@ -29,6 +29,11 @@ public partial class DeviceConnection : ObservableObject, IDisposable
|
||||
[ObservableProperty] private string apiLevel = "—";
|
||||
[ObservableProperty] private string notice = "";
|
||||
private Process? client, scrcpy;
|
||||
private bool screenWanted, usbBroken;
|
||||
private (string Path,int Size,int Fps,bool Audio,bool ViewOnly,int Port)? screenRequest;
|
||||
private int missingUsbPolls, recoveryAttempts, stablePolls;
|
||||
private DateTime nextRecovery=DateTime.MinValue;
|
||||
private CancellationTokenSource? recoveryCancellation;
|
||||
private WindowsUsbSession? usb;
|
||||
private string? transportFile, leaseFile;
|
||||
private readonly Action<string> log;
|
||||
@@ -94,10 +99,11 @@ public partial class DeviceConnection : ObservableObject, IDisposable
|
||||
if (disposed || !HasConnection || !await gate.WaitAsync(0)) return;
|
||||
try {
|
||||
if (scrcpy is { HasExited: true }) {
|
||||
if(scrcpy.ExitCode==0)screenWanted=false; else if(scrcpy.ExitCode==2 && Options.UsbMode)usbBroken=true;
|
||||
log($"手机控制窗口已关闭,退出码 {scrcpy.ExitCode}。");
|
||||
scrcpy.Dispose(); scrcpy = null; ScreenRunning = false; ScreenPort = null;
|
||||
}
|
||||
if (client is { HasExited: true } || usb is { HasExited: true }) {
|
||||
if (!Options.UsbMode && client is { HasExited: true }) {
|
||||
var reason = client is { HasExited: true } ? $"连接程序退出,代码 {client.ExitCode}" : "USB 模拟进程退出";
|
||||
await DisconnectCoreAsync(); Status = reason; Notice = reason + ",可重新连接。"; log(Notice); return;
|
||||
}
|
||||
@@ -119,11 +125,50 @@ public partial class DeviceConnection : ObservableObject, IDisposable
|
||||
"device" => "已连接 · 可调试和控制", "unauthorized" => "等待手机允许此电脑调试",
|
||||
"offline" => "设备离线 · 正在恢复连接", _ => "正在恢复连接 · 等待设备或网络"
|
||||
};
|
||||
if(Options.UsbMode) {
|
||||
var unauthorized=row?[1]=="unauthorized";
|
||||
if(Ready && !usbBroken && usb is not {HasExited:true} && client is not {HasExited:true}) {missingUsbPolls=0;if(++stablePolls>=10)recoveryAttempts=0;}
|
||||
else if(!unauthorized && (++missingUsbPolls>=3 || usbBroken || usb is {HasExited:true} || client is {HasExited:true}) && DateTime.UtcNow>=nextRecovery) {
|
||||
stablePolls=0;await RecoverUsbCoreAsync();return;
|
||||
}
|
||||
}
|
||||
if(Ready && screenWanted && !ScreenRunning && screenRequest is {} request && DateTime.UtcNow>=nextRecovery) {
|
||||
nextRecovery=DateTime.UtcNow.AddSeconds(5);
|
||||
var restoredPort=ConnectionPorts.Allocate(request.Port,new[]{Options.Port,Options.UsbPort??0});
|
||||
await StartScreenCoreAsync(request.Path,request.Size,request.Fps,request.Audio,request.ViewOnly,restoredPort);
|
||||
}
|
||||
if (Ready && !wasReady) { log("设备已就绪。"); await ReadInfoCoreAsync(); }
|
||||
} catch (OperationCanceledException) when (lifetime.IsCancellationRequested) { }
|
||||
catch (Exception error) { Ready = false; Notice = error.Message; log(error.Message); }
|
||||
finally { gate.Release(); }
|
||||
}
|
||||
private async Task RecoverUsbCoreAsync()
|
||||
{
|
||||
recoveryCancellation?.Dispose();
|
||||
recoveryCancellation=CancellationTokenSource.CreateLinkedTokenSource(lifetime.Token);
|
||||
var cancellation=recoveryCancellation.Token;
|
||||
nextRecovery=DateTime.UtcNow.AddSeconds(new[]{2,4,8,16,30}[Math.Min(recoveryAttempts++,4)]);
|
||||
Status="USB 会话中断 · 正在重新挂载";Ready=false;missingUsbPolls=0;
|
||||
log($"USB 自动恢复,第 {recoveryAttempts} 次。");
|
||||
try {
|
||||
await StopScreenCoreAsync(false);
|
||||
if(usb!=null){await usb.StopAsync(log);usb.Dispose();usb=null;}
|
||||
cancellation.ThrowIfCancellationRequested();
|
||||
if(client is null || client.HasExited) {
|
||||
client?.Dispose();
|
||||
if(File.Exists(leaseFile!))File.Delete(leaseFile!);
|
||||
var info=ProcessTools.ClientStartInfo(Options.Client,Options.Adb,Options.Relay,DeviceId,RawEndpoint);
|
||||
foreach(var arg in new[]{"--transport",Options.RelayOnly?"relay":"auto","--status-file",transportFile!,"--no-auto-connect","--lease-status-file",leaseFile!})info.ArgumentList.Add(arg);
|
||||
client=Start(info);
|
||||
}
|
||||
var newPort=ConnectionPorts.Allocate(Options.UsbPort is >=65535 ?3240:Options.UsbPort!.Value+1,new[]{Options.Port,ScreenPort??0});
|
||||
Options=Options with {UsbPort=newPort};OnPropertyChanged(nameof(PortSummary));
|
||||
usb=new WindowsUsbSession(DeviceId);
|
||||
await usb.StartAsync(Options.Usbip,newPort,RawEndpoint,leaseFile!,log,cancellation);
|
||||
Endpoint=usb.Serial;usbBroken=false;Status="USB 已重新挂载 · 等待 ADB 就绪";
|
||||
} catch(OperationCanceledException) when(cancellation.IsCancellationRequested) { }
|
||||
catch(Exception error){Notice="USB 恢复失败,稍后重试:"+error.Message;log(Notice);}
|
||||
}
|
||||
public void MonitoringFailed(string message) { Ready = false; Status = "ADB 检测失败"; Notice = message; }
|
||||
public Task ReadInfoAsync() => Exclusive(ReadInfoCoreAsync);
|
||||
private async Task ReadInfoCoreAsync()
|
||||
@@ -136,7 +181,8 @@ public partial class DeviceConnection : ObservableObject, IDisposable
|
||||
ApiLevel = lines.ElementAtOrDefault(2)?.Trim() ?? "未知";
|
||||
Notice = "设备信息已更新。";
|
||||
}
|
||||
public Task StartScreenAsync(string path, int size, int fps, bool audio, bool viewOnly, int port) => Exclusive(async () =>
|
||||
public Task StartScreenAsync(string path, int size, int fps, bool audio, bool viewOnly, int port) => Exclusive(()=>StartScreenCoreAsync(path,size,fps,audio,viewOnly,port));
|
||||
private async Task StartScreenCoreAsync(string path, int size, int fps, bool audio, bool viewOnly, int port)
|
||||
{
|
||||
if (!Ready || Endpoint == null || ScreenRunning) return;
|
||||
if (size is < 256 or > 8192 || fps is < 1 or > 240) throw new InvalidOperationException("分辨率范围 256–8192,帧率范围 1–240。");
|
||||
@@ -145,19 +191,22 @@ public partial class DeviceConnection : ObservableObject, IDisposable
|
||||
var args = new List<string> { "--serial", Endpoint, "--force-adb-forward", "--window-title", $"ADS · {DeviceId}", "--max-size", size.ToString(), "--max-fps", fps.ToString(), "--port", port.ToString() };
|
||||
if (!audio) args.Add("--no-audio"); if (viewOnly) args.Add("--no-control");
|
||||
var info = ProcessTools.CreateStartInfo(executable, args); info.Environment["ADB"] = Options.Adb;
|
||||
screenRequest=(path,size,fps,audio,viewOnly,port);screenWanted=true;
|
||||
scrcpy = Start(info); ScreenPort = port; ScreenRunning = true; Notice = "手机控制窗口已启动。"; log(Notice);
|
||||
});
|
||||
public Task StopScreenAsync() => Exclusive(StopScreenCoreAsync);
|
||||
private async Task StopScreenCoreAsync()
|
||||
}
|
||||
public Task StopScreenAsync() {screenWanted=false;return Exclusive(()=>StopScreenCoreAsync());}
|
||||
private async Task StopScreenCoreAsync(bool cancelResume=true)
|
||||
{
|
||||
if(cancelResume)screenWanted=false;
|
||||
var current = scrcpy; scrcpy = null;
|
||||
try { await ProcessTools.StopAsync(current); }
|
||||
finally { ScreenRunning = false; ScreenPort = null; }
|
||||
}
|
||||
public Task DisconnectAsync() => Exclusive(DisconnectCoreAsync);
|
||||
public Task DisconnectAsync() {screenWanted=false;recoveryCancellation?.Cancel();return Exclusive(DisconnectCoreAsync);}
|
||||
// Shutdown must also work after the shared cancellation token has been cancelled.
|
||||
public async Task ShutdownAsync()
|
||||
{
|
||||
screenWanted=false;recoveryCancellation?.Cancel();
|
||||
await gate.WaitAsync();
|
||||
try { await DisconnectCoreAsync(); }
|
||||
finally { gate.Release(); }
|
||||
|
||||
@@ -454,6 +454,17 @@ public partial class MainViewModel : ObservableObject, IDisposable
|
||||
ToolsStatus = string.Join(" · ", results); Notice = ToolsStatus;
|
||||
});
|
||||
|
||||
public void PersistSelectedPaths()
|
||||
{
|
||||
try {
|
||||
var selected=DesktopPaths.LoadSettings(settingsFile);
|
||||
selected.Client=ClientPath;selected.Adb=AdbPath;selected.Scrcpy=ScrcpyPath;
|
||||
selected.UsbipPath=UsbipPath;selected.CredentialFile=credentialFile;
|
||||
DesktopPaths.SaveSettings(settingsFile,selected);
|
||||
Notice="文件位置已保存。";
|
||||
}catch(Exception error){Report(error);}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Save()
|
||||
{
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
<TextBlock Text="可选 USB 模拟 · Windows" Classes="section"/>
|
||||
<CheckBox x:Name="UsbModeCheck" Content="将远程手机挂载为本机 USB ADB 设备" IsChecked="{Binding UsbMode}"/>
|
||||
<TextBlock Text="需要安装 USBip 虚拟控制器驱动。仅模拟 ADB 接口;首次使用仍需手机授权,修改在下次连接生效。" Classes="label" TextWrapping="Wrap"/>
|
||||
<TextBlock Text="usbip.exe 路径"/><TextBox Text="{Binding UsbipPath}" Watermark="C:\Program Files\USBip\usbip.exe"/>
|
||||
<TextBlock Text="usbip.exe 路径"/><Grid ColumnDefinitions="*,Auto"><TextBox Text="{Binding UsbipPath}" Watermark="usbip.exe"/><Button Grid.Column="1" Content="选择" Tag="usbip" Click="ChooseToolClick"/></Grid>
|
||||
<Grid ColumnDefinitions="*,180"><TextBlock Text="起始 USB/IP 端口(自动分配)" VerticalAlignment="Center"/><NumericUpDown Grid.Column="1" Value="{Binding UsbPort}" Minimum="1024" Maximum="65535"/></Grid>
|
||||
<TextBlock Text="驱动安装方式见项目 docs/windows-usb.md;默认网络 ADB 模式不需要此组件。" Classes="label" TextWrapping="Wrap"/>
|
||||
</StackPanel></Border>
|
||||
|
||||
@@ -20,7 +20,7 @@ public partial class MainWindow : Window
|
||||
Title = "选择客户端凭据 client.env", AllowMultiple = false,
|
||||
FileTypeFilter = [new FilePickerFileType("环境配置文件") { Patterns = ["*.env"] }, FilePickerFileTypes.All]
|
||||
});
|
||||
if (files.FirstOrDefault()?.TryGetLocalPath() is { } path) vm.LoadCredentials(path);
|
||||
if (files.FirstOrDefault()?.TryGetLocalPath() is { } path) { vm.LoadCredentials(path); vm.PersistSelectedPaths(); }
|
||||
}
|
||||
catch { vm.Notice = "无法打开凭据文件,请检查文件访问权限。"; }
|
||||
}
|
||||
@@ -36,8 +36,9 @@ public partial class MainWindow : Window
|
||||
{
|
||||
case "client": vm.ClientPath = path; break;
|
||||
case "adb": vm.AdbPath = path; break;
|
||||
case "scrcpy": vm.ScrcpyPath = path; break;
|
||||
case "scrcpy": vm.ScrcpyPath = path; break; case "usbip": vm.UsbipPath = path; break;
|
||||
}
|
||||
vm.PersistSelectedPaths();
|
||||
}
|
||||
catch { vm.Notice = "无法选择工具,请检查文件访问权限。"; }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user