Add opt-in physical USB device enrollment and remembered choices in 0.2.7
This commit is contained in:
1 parent
dc29a20a41
commit
208d37b7d8
20 files changed
+515
-18
No files matched your search
@@ -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});
|
||||
|
||||
@@ -171,6 +171,21 @@ class _AgentViewState extends State<AgentView> {
|
||||
Wrap(
|
||||
children: [
|
||||
button('读取配置', m.loadConfig, enabled: m.canManage),
|
||||
button(
|
||||
'开启 USB 自动注册',
|
||||
() => m.setAutoUsb(true),
|
||||
enabled: m.canManage,
|
||||
),
|
||||
button(
|
||||
'关闭 USB 自动注册',
|
||||
() => m.setAutoUsb(false),
|
||||
enabled: m.canManage,
|
||||
),
|
||||
button(
|
||||
'取消所选 USB 设备的忽略',
|
||||
m.unignoreUsb,
|
||||
enabled: m.canManage,
|
||||
),
|
||||
button(
|
||||
'重启 Agent',
|
||||
m.restart,
|
||||
|
||||
Reference in new issue
Block a user