feat: migrate Flutter to Cupertino with daily logs and computer groups
This commit is contained in:
1 parent
c568749d23
commit
87e1fff59b
22 files changed
+808
-55
No files matched your search
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../data/manager_repository.dart';
|
||||
import '../data/agent_repository.dart';
|
||||
import '../data/daily_log.dart';
|
||||
import '../data/agent_service.dart';
|
||||
import 'agent_model.dart';
|
||||
|
||||
@@ -11,23 +12,50 @@ import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
DailyLog defaultLog() => DailyLog(
|
||||
Directory(
|
||||
p.join(
|
||||
Platform.environment['LOCALAPPDATA'] ??
|
||||
p.join(
|
||||
Platform.environment['HOME'] ?? Directory.systemTemp.path,
|
||||
'.local',
|
||||
'share',
|
||||
),
|
||||
'TTSTD',
|
||||
'ADS-Flutter',
|
||||
'logs',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
class ManagerModel extends ChangeNotifier {
|
||||
late final ManagerRepository repository;
|
||||
late final AgentModel agents;
|
||||
List<Device> devices = [];
|
||||
List<Map<String, dynamic>> nodes = [];
|
||||
final List<String> logs = [];
|
||||
late final DailyLog diskLog;
|
||||
String get logDirectory => diskLog.directory.path;
|
||||
final Set<String> pending = {};
|
||||
String notice = '正在初始化', adbListing = '';
|
||||
bool refreshing = false, closing = false, polling = false;
|
||||
Timer? timer;
|
||||
int ticks = 0;
|
||||
ManagerModel() {
|
||||
ManagerModel({DailyLog? logWriter}) {
|
||||
diskLog = logWriter ?? defaultLog();
|
||||
repository = ManagerRepository(log);
|
||||
agents = AgentModel(AgentRepository(AgentService(repository)));
|
||||
agents.onLog = (text) => log("[Agent] $text");
|
||||
}
|
||||
void log(String text) {
|
||||
logs.insert(0, '${DateTime.now().toString().substring(11, 19)} $text');
|
||||
var safe = agents.repository.redact(text);
|
||||
for (final secret in [repository.token, agents.enrollmentToken]) {
|
||||
if (secret.isNotEmpty) safe = safe.replaceAll(secret, '[REDACTED]');
|
||||
}
|
||||
logs.insert(0, '${DateTime.now().toString().substring(11, 19)} $safe');
|
||||
diskLog.add(
|
||||
safe.length > 16384 ? '${safe.substring(0, 16384)} [truncated]' : safe,
|
||||
);
|
||||
if (logs.length > 500) {
|
||||
logs.removeLast();
|
||||
}
|
||||
@@ -72,6 +100,7 @@ class ManagerModel extends ChangeNotifier {
|
||||
notice = '准备就绪';
|
||||
});
|
||||
await refresh();
|
||||
log('ADS Flutter / Cupertino 已启动,本地日志目录:$logDirectory');
|
||||
timer = Timer.periodic(const Duration(seconds: 3), (_) async {
|
||||
if (closing || refreshing || polling) {
|
||||
return;
|
||||
@@ -145,5 +174,6 @@ class ManagerModel extends ChangeNotifier {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
}
|
||||
await repository.shutdown();
|
||||
await diskLog.flush();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user