Add opt-in physical USB device enrollment and remembered choices in 0.2.7

This commit is contained in:
tongtong committed 2026-11-14 04:06:01 +08:00
1 parent dc29a20a41
commit 208d37b7d8
20 files changed
+515 -18

No files matched your search

+34
View File
@@ -192,6 +192,40 @@ class AgentModel extends ChangeNotifier {
.convert(await _call({'op': 'config_get'}));
notice = '已读取配置,凭据不在配置中。';
});
Future<void> setAutoUsb(bool enabled) => run(() async {
final config = Map<String, Object?>.from(
await _call({'op': 'config_get'}) as Map,
);
final expected = Map<String, Object?>.from(config);
config['auto_register_usb'] = enabled;
await _call({
'op': 'config_set',
'config': config,
'expected_config': expected,
});
configText = const JsonEncoder.withIndent(' ').convert(config);
await _refresh();
notice = enabled ? '已开启真实 USB 自动注册。' : '已关闭自动注册,已有设备保留。';
});
Future<void> unignoreUsb() => run(() async {
final serial = adbSerial.trim();
if (serial.isEmpty) throw StateError('请先发现并选择需要取消忽略的 USB 设备');
final config = Map<String, Object?>.from(
await _call({'op': 'config_get'}) as Map,
);
final expected = Map<String, Object?>.from(config);
config['ignored_usb_serials'] =
(config['ignored_usb_serials'] as List? ?? [])
.where((s) => s != serial)
.toList();
await _call({
'op': 'config_set',
'config': config,
'expected_config': expected,
});
configText = const JsonEncoder.withIndent(' ').convert(config);
notice = '已取消该设备的忽略记录;开启自动注册后将重新检查。';
});
Future<void> saveConfig() => run(() async {
final data = jsonDecode(configText) as Map<String, Object?>;
await _call({'op': 'config_set', 'config': data});