Sync desktop daily logs and fix emulator ADB upstream connections
This commit is contained in:
1 parent
87e1fff59b
commit
0d269f3ded
15 files changed
+139
-12
No files matched your search
@@ -0,0 +1,17 @@
|
||||
using Ads.Desktop;
|
||||
using Xunit;
|
||||
namespace Ads.Desktop.Tests;
|
||||
public class DailyLogTests {
|
||||
[Fact] public void PersistsAndCleansOnlyOwnedExpiredLogs() {
|
||||
var folder=Path.Combine(Path.GetTempPath(),Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(folder);
|
||||
try {
|
||||
File.WriteAllText(Path.Combine(folder,"ads-2000-01-01.1.log"),"old");
|
||||
File.WriteAllText(Path.Combine(folder,"ads-2000-01-01-custom.log"),"keep");
|
||||
new DailyLog(folder).Write("connection diagnostic");
|
||||
Assert.False(File.Exists(Path.Combine(folder,"ads-2000-01-01.1.log")));
|
||||
Assert.True(File.Exists(Path.Combine(folder,"ads-2000-01-01-custom.log")));
|
||||
Assert.Contains("connection diagnostic",File.ReadAllText(Path.Combine(folder,$"ads-{DateTime.Now:yyyy-MM-dd}.log")));
|
||||
} finally { Directory.Delete(folder,true); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Text;
|
||||
namespace Ads.Desktop;
|
||||
public sealed class DailyLog
|
||||
{
|
||||
readonly string folder; readonly object gate = new(); DateTime cleanedDate;
|
||||
public string Folder => folder;
|
||||
public DailyLog(string path) => folder = path;
|
||||
public void Write(string message)
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(folder); var now = DateTime.Now; var name = $"ads-{now:yyyy-MM-dd}";
|
||||
if (cleanedDate != now.Date)
|
||||
{
|
||||
foreach (var file in Directory.EnumerateFiles(folder, "ads-*.log"))
|
||||
{
|
||||
var text = Path.GetFileName(file);
|
||||
if (System.Text.RegularExpressions.Regex.IsMatch(text, @"^ads-\d{4}-\d{2}-\d{2}(\.[1-4])?\.log$") && DateTime.TryParseExact(text.Substring(4, 10), "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out var date) && date < now.Date.AddDays(-13)) File.Delete(file);
|
||||
}
|
||||
cleanedDate = now.Date;
|
||||
}
|
||||
var path = Path.Combine(folder, name + ".log");
|
||||
if (File.Exists(path) && new FileInfo(path).Length >= 5 * 1024 * 1024)
|
||||
{
|
||||
var oldest = Path.Combine(folder, name + ".4.log"); if (File.Exists(oldest)) File.Delete(oldest);
|
||||
for (var i = 3; i >= 1; i--) { var old = Path.Combine(folder, $"{name}.{i}.log"); if (File.Exists(old)) File.Move(old, Path.Combine(folder, $"{name}.{i + 1}.log")); }
|
||||
File.Move(path, Path.Combine(folder, name + ".1.log"));
|
||||
}
|
||||
if (message.Length > 16384) message = message[..16384] + " [truncated]";
|
||||
File.AppendAllText(path, $"{now:O} {message}\n", Encoding.UTF8);
|
||||
}
|
||||
catch (IOException) { }
|
||||
catch (UnauthorizedAccessException) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,9 @@ using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Ads.Desktop;
|
||||
|
||||
public sealed record DeviceItem(string Id, bool Busy, bool IsLocal, bool Online = true, string LocalSummary = "")
|
||||
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 ? "在线 · 其他客户端使用中" : "在线 · 可连接";
|
||||
}
|
||||
|
||||
@@ -143,9 +144,13 @@ public partial class MainViewModel : ObservableObject, IDisposable
|
||||
return text;
|
||||
}
|
||||
|
||||
private DailyLog? dailyLog;
|
||||
public string LogFolder => Path.Combine(folder,"logs");
|
||||
[RelayCommand] private void OpenLogFolder(){try{Directory.CreateDirectory(LogFolder);Process.Start(new ProcessStartInfo(LogFolder){UseShellExecute=true});}catch(Exception error){Report(error);}}
|
||||
private void Log(string message)
|
||||
{
|
||||
var line = $"{DateTime.Now:HH:mm:ss} {Redact(message)}";
|
||||
var safe=Redact(message);(dailyLog ??= new DailyLog(LogFolder)).Write(safe);
|
||||
var line = $"{DateTime.Now:HH:mm:ss} {safe}";
|
||||
void Append() { if (disposed) return; Logs.Add(line); while (Logs.Count > 1000) Logs.RemoveAt(0); }
|
||||
if (Dispatcher.UIThread.CheckAccess()) Append(); else Dispatcher.UIThread.Post(Append);
|
||||
}
|
||||
@@ -202,7 +207,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
|
||||
Devices.Clear();
|
||||
foreach (var row in rows) {
|
||||
var connection = sessions.GetValueOrDefault(row.Id);
|
||||
Devices.Add(new DeviceItem(row.Id, row.Busy || connection?.HasConnection == true, connection?.HasConnection == true, true, connection?.Status ?? ""));
|
||||
Devices.Add(new DeviceItem(row.Id, row.Busy || connection?.HasConnection == true, connection?.HasConnection == true, true, connection?.Status ?? "",row.ComputerName,row.AgentId));
|
||||
}
|
||||
foreach (var local in Connections.Where(c => rows.All(r => r.Id != c.DeviceId)))
|
||||
Devices.Add(new DeviceItem(local.DeviceId, true, true, false, local.Status));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<TextBlock Text="连接远程手机,在本机调试与控制" Classes="label"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Spacing="8">
|
||||
<Border Height="3" HorizontalAlignment="Stretch"><ProgressBar IsIndeterminate="True" IsVisible="{Binding IsRefreshing}" Height="3"/></Border>
|
||||
<TextBlock x:Name="RelayStatusText" Text="{Binding RelayStatus}" HorizontalAlignment="Right" Foreground="#66D9C0"/>
|
||||
<StackPanel Orientation="Horizontal"><Button x:Name="RefreshButton" Content="刷新设备" Command="{Binding RefreshCommand}"/><Button Content="保存配置" Command="{Binding SaveCommand}"/></StackPanel>
|
||||
</StackPanel>
|
||||
@@ -27,7 +28,7 @@
|
||||
<Grid RowDefinitions="Auto,*,Auto,Auto,Auto">
|
||||
<TextBlock Text="在线设备" Classes="section"/>
|
||||
<ListBox x:Name="DeviceList" Grid.Row="1" ItemsSource="{Binding Devices}" SelectedItem="{Binding SelectedDevice}" Margin="0,14,0,12" Background="Transparent">
|
||||
<ListBox.ItemTemplate><DataTemplate><StackPanel Margin="5,10" Spacing="6"><TextBlock Text="{Binding Id}" FontSize="17" TextWrapping="Wrap"/><TextBlock Text="{Binding Description}" Classes="label" TextWrapping="Wrap"/></StackPanel></DataTemplate></ListBox.ItemTemplate>
|
||||
<ListBox.ItemTemplate><DataTemplate><StackPanel Margin="5,10" Spacing="6"><TextBlock Text="{Binding Id}" FontSize="17" TextWrapping="Wrap"/><TextBlock Text="{Binding ComputerLabel}" Classes="label" TextWrapping="Wrap"/><TextBlock Text="{Binding Description}" Classes="label" TextWrapping="Wrap"/></StackPanel></DataTemplate></ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<TextBlock Grid.Row="2" Text="{Binding ConnectionSummary}" Foreground="#66D9C0" Margin="0,0,0,8" TextWrapping="Wrap"/>
|
||||
<TextBlock Grid.Row="3" Text="{Binding DeviceSummary}" Classes="label" TextWrapping="Wrap"/>
|
||||
@@ -146,7 +147,7 @@
|
||||
</TabItem>
|
||||
<TabItem Header="运行日志">
|
||||
<Grid RowDefinitions="Auto,*" Margin="0,16,0,0">
|
||||
<StackPanel Orientation="Horizontal"><Button Content="清空日志" Command="{Binding ClearLogsCommand}"/><Button Content="导出日志" Command="{Binding ExportLogsCommand}"/></StackPanel>
|
||||
<StackPanel Orientation="Horizontal"><Button Content="打开日志文件夹" Command="{Binding OpenLogFolderCommand}"/><Button Content="清空日志" Command="{Binding ClearLogsCommand}"/><Button Content="导出日志" Command="{Binding ExportLogsCommand}"/></StackPanel>
|
||||
<ListBox Grid.Row="1" ItemsSource="{Binding Logs}" Margin="0,8,0,0" FontFamily="Cascadia Mono,Consolas" FontSize="12"><ListBox.ItemTemplate><DataTemplate><TextBlock Text="{Binding}" TextWrapping="Wrap"/></DataTemplate></ListBox.ItemTemplate></ListBox>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@@ -48,7 +48,7 @@ public sealed record RelayOptions(Uri BaseUri, string Origin, string Token)
|
||||
}.Uri;
|
||||
}
|
||||
|
||||
public sealed record RelayDevice(string Id, bool Busy);
|
||||
public sealed record RelayDevice(string Id, bool Busy, [property:System.Text.Json.Serialization.JsonPropertyName("agent_id")] string AgentId="", [property:System.Text.Json.Serialization.JsonPropertyName("computer_name")] string ComputerName="");
|
||||
|
||||
public sealed record RelayNode(string Id, bool Healthy, int Sessions, int Capacity)
|
||||
{
|
||||
@@ -111,6 +111,6 @@ public static class RelayApi
|
||||
if (devices.Any(d => string.IsNullOrWhiteSpace(d.Id) || d.Id.Length > 128 ||
|
||||
d.Id.Any(c => !char.IsAsciiLetterOrDigit(c) && c != '-' && c != '_' && c != '.')))
|
||||
throw new InvalidOperationException("中继返回了无效的设备 ID。");
|
||||
return devices.OrderBy(d => d.Id, StringComparer.Ordinal).ToArray();
|
||||
return devices.OrderBy(d => d.ComputerName, StringComparer.OrdinalIgnoreCase).ThenBy(d => d.AgentId, StringComparer.Ordinal).ThenBy(d => d.Id, StringComparer.Ordinal).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -92,3 +92,5 @@ USB 连续缺失 3 轮、USB 后端退出或投屏报告设备断开后,自动
|
||||
USB 会话后端已按操作系统选择:Windows 使用已签名 USBip 控制器,Linux 使用系统 usbip/vhci_hcd,挂载时通过 pkexec 请求桌面授权。转发和 ads-usb 仍以当前用户运行,断开时关闭本次导出,避免按可能复用的控制器端口误断其他设备。Linux 需安装 usbip、polkit、ADB 和兼容版本 scrcpy;首次授权需在手机确认。
|
||||
|
||||
192.168.5.224 工程位于 `/home/tt/TongTongStudio/AndroidDeviceStreaming`,自包含发行目录为 `bin/desktop-linux-x64/`。已在 TT 的 X11 会话启动成功;已有 .NET 8.0.16 runtime 和 SDK 8.0.409 位于 `/home/tt/.dotnet`,SSH PATH 未包含此目录。工程要求 SDK 8.0.428,远程源码构建尚需安装该版本;自包含发行版无需安装 runtime。
|
||||
|
||||
桌面日志界面提供“打开日志文件夹”。Avalonia 与 Flutter 均按天保存日志,单文件达到 5 MiB 后滚动,每日最多 5 份,保留最近 14 天。设备列表显示所属电脑及 Agent。Windows 安装包默认安装到 `%LOCALAPPDATA%/Programs/TongTongStudio/ADS-{Edition}`;用户配置和日志位置保持兼容。升级保持原 AppId,安装目录不再自动沿用旧的 TTSTD 路径。
|
||||
Reference in new issue
Block a user