feat: add headless agent management to CLI and both desktop clients
This commit is contained in:
1 parent
e91fa0235c
commit
6916dd54fb
50 files changed
+4837
-148
No files matched your search
@@ -3,9 +3,17 @@ import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../data/manager_repository.dart';
|
||||
import '../data/agent_repository.dart';
|
||||
import '../data/agent_service.dart';
|
||||
import 'agent_model.dart';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class ManagerModel extends ChangeNotifier {
|
||||
late final ManagerRepository repository;
|
||||
late final AgentModel agents;
|
||||
List<Device> devices = [];
|
||||
List<Map<String, dynamic>> nodes = [];
|
||||
final List<String> logs = [];
|
||||
@@ -16,6 +24,7 @@ class ManagerModel extends ChangeNotifier {
|
||||
int ticks = 0;
|
||||
ManagerModel() {
|
||||
repository = ManagerRepository(log);
|
||||
agents = AgentModel(AgentRepository(AgentService(repository)));
|
||||
}
|
||||
void log(String text) {
|
||||
logs.insert(0, '${DateTime.now().toString().substring(11, 19)} $text');
|
||||
@@ -38,6 +47,13 @@ class ManagerModel extends ChangeNotifier {
|
||||
Future<void> init() async {
|
||||
await action(() async {
|
||||
await repository.init();
|
||||
await agents.initialize(
|
||||
adminFile: repository.root == null
|
||||
? p.join(p.dirname(Platform.resolvedExecutable), 'admin.env')
|
||||
: p.join(repository.root!.path, 'config', 'private', 'admin.env'),
|
||||
server: repository.settings.server,
|
||||
origin: repository.settings.origin,
|
||||
);
|
||||
notice = '准备就绪';
|
||||
});
|
||||
await refresh();
|
||||
@@ -99,8 +115,16 @@ class ManagerModel extends ChangeNotifier {
|
||||
'-l',
|
||||
]);
|
||||
});
|
||||
@override
|
||||
void dispose() {
|
||||
agents.dispose();
|
||||
timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> shutdown() async {
|
||||
closing = true;
|
||||
agents.dispose();
|
||||
timer?.cancel();
|
||||
while (pending.isNotEmpty) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
|
||||
Reference in new issue
Block a user