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

+16 -7
View File
@@ -13,8 +13,13 @@ public partial class App : Application
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var vm = new MainViewModel();
var window = new MainWindow { DataContext = vm };
var localAgentMode = desktop.Args?.Contains("--agent-tray") == true;
var vm = new MainViewModel(backgroundMonitoring: !localAgentMode, loadLocalCredentials: !localAgentMode);
Window window;
if(localAgentMode) {
vm.AgentManager.LocalMode=true;vm.AgentManager.StartMonitoring();
window=new Window {Title="ADS · 被控端 Agent 管理",Width=1100,Height=850,MinWidth=900,MinHeight=650,Background=Avalonia.Media.Brush.Parse("#10151F"),Content=new AgentManagementView{DataContext=vm.AgentManager,Margin=new Avalonia.Thickness(22)}};
} else window = new MainWindow { DataContext = vm };
desktop.MainWindow = window;
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
void Show() { window.Show(); window.WindowState = WindowState.Normal; window.Activate(); }
@@ -26,19 +31,23 @@ public partial class App : Application
finally { desktop.Shutdown(); }
}
var menu = new NativeMenu();
var show = new NativeMenuItem("打开设备工作台"); show.Click += (_, _) => Show(); menu.Items.Add(show);
menu.Items.Add(new NativeMenuItem("断开全部设备") { Command = vm.DisconnectAllCommand });
var show = new NativeMenuItem(localAgentMode ? "打开本机 Agent 管理" : "打开设备工作台"); show.Click += (_, _) => Show(); menu.Items.Add(show);
if(localAgentMode)menu.Items.Add(new NativeMenuItem("重启本机 Agent") {Command=vm.AgentManager.RestartAgentCommand});
else menu.Items.Add(new NativeMenuItem("断开全部设备") { Command = vm.DisconnectAllCommand });
menu.Items.Add(new NativeMenuItemSeparator());
var quit = new NativeMenuItem("退出并断开连接");
var quit = new NativeMenuItem(localAgentMode ? "退出托盘(Agent 继续运行)" : "退出并断开连接");
quit.Click += async (_, _) => await QuitAsync();
menu.Items.Add(quit);
using var stream = Avalonia.Platform.AssetLoader.Open(new Uri("avares://Ads.Desktop/Assets/app.png"));
var tray = new TrayIcon { ToolTipText = "ADS · Android 设备工作台", Icon = new WindowIcon(stream), Menu = menu, Command = new RelayCommand(Show) };
var tray = new TrayIcon { ToolTipText = localAgentMode ? "ADS · 本机 Agent 管理" : "ADS · Android 设备工作台", Icon = new WindowIcon(stream), Menu = menu, Command = new RelayCommand(Show) };
TrayIcon.SetIcons(this, new TrayIcons { tray });
vm.PropertyChanged += (_, change) => {
if (change.PropertyName is nameof(vm.ConnectionSummary))
if (!localAgentMode && change.PropertyName is nameof(vm.ConnectionSummary))
tray.ToolTipText = "ADS · " + vm.ConnectionSummary;
};
if(localAgentMode)vm.AgentManager.PropertyChanged += (_, change) => {
if(change.PropertyName is nameof(AgentManagementViewModel.Notice)) tray.ToolTipText="ADS Agent · "+vm.AgentManager.Notice;
};
window.Closing += async (_, e) => {
if (quitting) return;
e.Cancel = true;