feat: add headless agent management to CLI and both desktop clients

This commit is contained in:
tongtong committed 2026-11-12 21:17:44 +08:00
1 parent e91fa0235c
commit 6916dd54fb
50 files changed
+4837 -148

No files matched your search

+4 -2
View File
@@ -52,6 +52,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
[ObservableProperty] private bool isWorking;
[ObservableProperty] private bool isRefreshing;
public AgentManagementViewModel AgentManager { get; }
public ObservableCollection<RelayNode> RelayNodes { get; } = new();
public ObservableCollection<DeviceItem> Devices { get; } = new();
public ObservableCollection<string> Logs { get; } = new();
@@ -106,6 +107,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
if (File.Exists(credentialFile)) LoadCredentials(credentialFile, useOrigin: false);
}
Notice = Token.Length >= 32 ? "配置已就绪,正在等待刷新设备。" : "请在连接配置中导入 client.env。";
AgentManager = new AgentManagementViewModel(() => (Server, Origin), Log, backgroundMonitoring, loadLocalCredentials);
timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
timer.Tick += async (_, _) => await MonitorAsync();
if (backgroundMonitoring) timer.Start();
@@ -484,7 +486,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
public async Task ShutdownAsync()
{
timer.Stop(); lifetime.Cancel();
AgentManager.Dispose(); timer.Stop(); lifetime.Cancel();
await connectionGate.WaitAsync();
try { await DisconnectAllCoreAsync(); }
finally { connectionGate.Release(); }
@@ -493,7 +495,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
public void Dispose()
{
if (disposed) return;
disposed = true; timer.Stop(); lifetime.Cancel();
disposed = true; AgentManager.Dispose(); timer.Stop(); lifetime.Cancel();
foreach (var session in sessions.Values) { session.PropertyChanged -= ConnectionChanged; session.Dispose(); }
sessions.Clear(); Connections.Clear();
lifetime.Dispose();