Add LAN debugging and persistent logs

This commit is contained in:
TongTongStudio committed 2026-11-29 09:17:46 +08:00
1 parent 9cf29c11ab
commit 9153bc839e
4 files changed
+364 -16

No files matched your search

+39 -2
View File
@@ -3,7 +3,7 @@ using System.Text.Json;
internal sealed record EmulatorInstance(
string Name, string Type, string Version, string ApiVersion,
string Resolution, string ScreenSize, string InstancePath, bool IsRunning)
string Resolution, string ScreenSize, string InstancePath, string HdcPort, bool IsRunning)
{
public string Running => IsRunning ? "运行中" : "已停止";
public override string ToString() => $"{Name} | {Type} | {Version} | {Running}";
@@ -41,6 +41,42 @@ internal static class EmulatorCli
.FirstOrDefault(path => Path.IsPathFullyQualified(path) && File.Exists(path)) ?? name;
}
internal static void StartDetached(string executable, string[] args, Action<string> log)
{
var launchLog = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "emulator-manager-launch.log");
log($"› Emulator {string.Join(" ", args.Select(arg => JsonSerializer.Serialize(arg)))}(独立进程)");
if (OperatingSystem.IsWindows())
{
var info = new ProcessStartInfo(executable)
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = false,
RedirectStandardError = false
};
foreach (var argument in args)
info.ArgumentList.Add(argument);
using var _ = Process.Start(info);
return;
}
var command = string.Join(" ", args.Select(Quote));
var shell = $"setsid {Quote(executable)} {command} >> {Quote(launchLog)} 2>&1 < /dev/null &";
using var shellProcess = Process.Start(new ProcessStartInfo("/bin/sh")
{
UseShellExecute = false,
CreateNoWindow = true,
ArgumentList = { "-c", shell }
}) ?? throw new InvalidOperationException("无法启动独立进程。");
shellProcess.WaitForExit();
log($"模拟器输出写入 {launchLog}");
}
private static string Quote(string value) =>
"'" + value.Replace("'", "'\\''", StringComparison.Ordinal) + "'";
internal static async Task<string> RunAsync(
string executable, string[] args, Action<string> log, CancellationToken cancellation)
{
@@ -98,7 +134,8 @@ internal static class EmulatorCli
internal static EmulatorInstance[] Instances(string output) => Parse(output, row => new EmulatorInstance(
Field(row, "name"), Field(row, "deviceType"), Field(row, "os.osVersion"),
Field(row, "os.apiVersion"), Resolution(row), ScreenSize(row),
Field(row, "instancePath"), Field(row, "isRunning").Equals("true", StringComparison.OrdinalIgnoreCase)));
Field(row, "instancePath"), Field(row, "hw.hdc.port"),
Field(row, "isRunning").Equals("true", StringComparison.OrdinalIgnoreCase)));
private static string Resolution(JsonElement row)
{