diff --git a/EmulatorCli.cs b/EmulatorCli.cs index 109e36f..fc5b29b 100644 --- a/EmulatorCli.cs +++ b/EmulatorCli.cs @@ -51,7 +51,7 @@ internal static class EmulatorCli using var process = Process.Start(info) ?? throw new InvalidOperationException("无法启动 Emulator。"); process.StandardInput.Close(); var capture = args[0] is "-list" or "-imageList"; - var stdout = ReadAsync(process.StandardOutput, log, capture, cancellation); + var stdout = ReadAsync(process.StandardOutput, capture ? null : log, capture, cancellation); var stderr = ReadAsync(process.StandardError, log, false, cancellation); try { @@ -66,17 +66,21 @@ internal static class EmulatorCli } if (process.ExitCode != 0) + { + if (capture) + log(await stdout); throw new InvalidOperationException($"Emulator 退出码 {process.ExitCode}。请查看命令输出。"); + } return await stdout; } private static async Task ReadAsync( - StreamReader reader, Action log, bool capture, CancellationToken cancellation) + StreamReader reader, Action? log, bool capture, CancellationToken cancellation) { var output = new System.Text.StringBuilder(); while (await reader.ReadLineAsync(cancellation) is { } line) { - log(line); + log?.Invoke(line); if (capture) output.AppendLine(line); } diff --git a/MainWindow.cs b/MainWindow.cs index be0c0dd..a41aa69 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -1,5 +1,6 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Templates; using Avalonia.Layout; using Avalonia.Media; using Avalonia.Threading; @@ -7,15 +8,21 @@ using Avalonia.Threading; internal sealed class MainWindow : Window { private readonly TextBox executable = new() { Text = EmulatorCli.DefaultPath(), Watermark = "Emulator 可执行文件路径" }; - private readonly TextBox name = new() { Watermark = "实例名称", Width = 210 }; - private readonly TextBox deviceType = new() { Watermark = "设备类型,如 phone", Width = 170, Text = "phone" }; - private readonly TextBox version = new() { Watermark = "HarmonyOS 镜像版本", Width = 270 }; + private readonly TextBox targetName = new() { Watermark = "选择列表中的实例" }; + private readonly TextBox name = new() { Watermark = "例如 My Phone" }; + private readonly TextBox deviceType = new() { Watermark = "例如 phone", Text = "phone" }; + private readonly TextBox version = new() { Watermark = "例如 HarmonyOS 7.0.0(26.0.0)" }; private readonly CheckBox headless = new() { Content = "无窗口启动" }; private readonly ListBox instances = new() { MinHeight = 120 }; private readonly ListBox images = new() { MinHeight = 120 }; - private readonly ListBox output = new(); - private readonly TextBlock status = new() { Text = "就绪", VerticalAlignment = VerticalAlignment.Center }; - private readonly Button cancel = new() { Content = "取消命令", IsEnabled = false }; + private readonly ListBox output = new() { MaxHeight = 156, MinHeight = 104 }; + private readonly Button logToggle = new() { Content = "展开命令输出" }; + private readonly TextBlock status = new() + { + Text = "就绪", VerticalAlignment = VerticalAlignment.Center, + TextTrimming = TextTrimming.CharacterEllipsis + }; + private readonly Button cancel = new() { Content = "取消命令", IsVisible = false }; private readonly List