Add relay node management and pin manager header layout

- server: add, delete and set-default node endpoints writing cluster.json with validation

- deploy: grant ads-server write access to /etc/ads

- flutter: relay node page with admin token plumbing, stop reconnecting devices removed from device list

- flutter: fixed header heights and strut so tab switching never shifts refresh/notice
This commit is contained in:
tongtong committed 2026-11-16 16:44:58 +08:00
1 parent e12cb76d68
commit 0a04d5990f
9 files changed
+606 -75

No files matched your search

+326 -59
View File
@@ -24,7 +24,36 @@ class _ManagerViewState extends State<ManagerView> {
int page = 0;
String? screenDevice;
String search = '';
bool addingNode = false;
final nodeId = TextEditingController();
final nodeUrl = TextEditingController();
final nodeAddress = TextEditingController();
final nodePriority = TextEditingController(text: '100');
ManagerModel get m => widget.model;
@override
void dispose() {
for (final c in [nodeId, nodeUrl, nodeAddress, nodePriority]) {
c.dispose();
}
super.dispose();
}
Future<void> submitNode() async {
setState(() => addingNode = true);
try {
await m.addNode(
id: nodeId.text.trim(),
url: nodeUrl.text.trim(),
address: nodeAddress.text.trim(),
priority: int.tryParse(nodePriority.text.trim()) ?? 100,
);
} finally {
if (mounted) {
setState(() => addingNode = false);
}
}
}
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: m,
@@ -141,50 +170,71 @@ class _ManagerViewState extends State<ManagerView> {
Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(
horizontal: 28,
horizontal: 24,
vertical: 20,
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
[
'设备工作台',
'中继节点',
'本机 ADB',
'连接配置',
'运行日志',
'Agent 管理',
'内嵌投屏',
][page],
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.w700,
child: SizedBox(
height: 67,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
[
'设备工作台',
'中继节点',
'本机 ADB',
'连接配置',
'运行日志',
'Agent 管理',
'内嵌投屏',
][page],
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.w700,
height: 1.25,
),
strutStyle: const StrutStyle(
fontSize: 24,
height: 1.25,
forceStrutHeight: true,
),
),
),
),
const SizedBox(height: 5),
Text(
m.notice,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Color(0xFF66758D),
fontSize: 12,
const SizedBox(height: 5),
SizedBox(
height: 32,
child: Text(
m.notice,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Color(0xFF66758D),
fontSize: 12,
height: 1.3,
),
strutStyle: const StrutStyle(
fontSize: 12,
height: 1.3,
forceStrutHeight: true,
),
),
),
),
],
],
),
),
),
const SizedBox(width: 12),
OutlinedButton.icon(
onPressed: m.refreshing ? null : m.refresh,
icon: const Icon(Icons.refresh, size: 18),
label: Text(m.refreshing ? '同步中' : '刷新'),
),
],
const SizedBox(width: 12),
OutlinedButton.icon(
onPressed: m.refreshing ? null : m.refresh,
icon: const Icon(Icons.refresh, size: 18),
label: Text(m.refreshing ? '同步中' : '刷新'),
),
],
),
),
),
SizedBox(
@@ -508,27 +558,244 @@ class _ManagerViewState extends State<ManagerView> {
);
}
Widget nodes() => m.nodes.isEmpty
? const Center(child: Text('暂无中继节点,或服务尚未启用 v2 节点接口'))
: ListView.separated(
itemCount: m.nodes.length,
separatorBuilder: (_, index) => const SizedBox(height: 12),
itemBuilder: (_, i) {
final n = m.nodes[i];
return Card(
child: ListTile(
contentPadding: const EdgeInsets.all(20),
leading: Icon(
Icons.hub,
color: n['healthy'] == true ? Colors.teal : Colors.grey,
Widget nodes() {
final hint = m.nodeCredentialHint;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
child: Row(
children: [
const Icon(
Icons.hub_outlined,
size: 20,
color: Color(0xFF305DDB),
),
title: Text('${n["id"]}'),
subtitle: Text(n['healthy'] == true ? '在线' : '不可用'),
trailing: Text('通道 ${n["sessions"]} / ${n["capacity"]}'),
),
);
},
);
const SizedBox(width: 12),
const Expanded(
child: Text(
'中继节点由控制中心管理:新增、删除和设置默认节点会写入服务端 cluster.json,并影响后续连接优先尝试的路由。',
style: TextStyle(
fontSize: 12,
color: Color(0xFF66758D),
height: 1.4,
),
),
),
],
),
),
),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'新增节点',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
const SizedBox(height: 12),
Wrap(
spacing: 12,
runSpacing: 12,
children: [
SizedBox(
width: 150,
child: TextField(
controller: nodeId,
decoration: const InputDecoration(
labelText: '节点 ID',
hintText: 'relay-3',
),
),
),
SizedBox(
width: 320,
child: TextField(
controller: nodeUrl,
decoration: const InputDecoration(
labelText: '中继 URL',
hintText: 'wss://example.com/ads-relay',
),
),
),
SizedBox(
width: 210,
child: TextField(
controller: nodeAddress,
decoration: const InputDecoration(
labelText: '直连地址(可留空)',
hintText: '1.2.3.4:443',
),
),
),
SizedBox(
width: 110,
child: TextField(
controller: nodePriority,
decoration: const InputDecoration(labelText: '优先级'),
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
if (hint.isNotEmpty)
Expanded(
child: Text(
hint,
style: const TextStyle(
color: Color(0xFFB26A00),
fontSize: 12,
),
),
)
else
const Spacer(),
const SizedBox(width: 12),
FilledButton.icon(
onPressed: addingNode || hint.isNotEmpty
? null
: submitNode,
icon: const Icon(Icons.add, size: 18),
label: Text(addingNode ? '提交中' : '添加节点'),
),
],
),
],
),
),
),
const SizedBox(height: 16),
Expanded(
child: m.nodes.isEmpty
? const Center(child: Text('暂无中继节点,或服务尚未启用 v2 节点接口'))
: ListView.separated(
itemCount: m.nodes.length,
separatorBuilder: (_, index) => const SizedBox(height: 12),
itemBuilder: (_, i) {
final n = m.nodes[i];
final id = '${n['id']}';
final busy = m.pending.contains('node:$id');
final online = n['healthy'] == true;
final isDefault = n['default'] == true;
final address = '${n['connect_address'] ?? ''}';
return Card(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 14,
),
child: Row(
children: [
Icon(
Icons.hub,
color: online ? Colors.teal : Colors.grey,
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
id,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
if (isDefault)
Container(
margin: const EdgeInsets.only(
left: 8,
),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: const Color(0xFFE3EBFF),
borderRadius: BorderRadius.circular(
10,
),
),
child: const Text(
'默认',
style: TextStyle(
fontSize: 11,
color: Color(0xFF305DDB),
),
),
),
],
),
const SizedBox(height: 4),
Text(
'${n['url']}${address.isEmpty ? '' : ' · $address'}',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF66758D),
),
),
const SizedBox(height: 2),
Text(
'${online ? '在线' : '不可用'} · 通道 ${n['sessions']} / ${n['capacity']}',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF66758D),
),
),
],
),
),
const SizedBox(width: 12),
if (!isDefault)
TextButton.icon(
onPressed: busy
? null
: () => m.deviceAction(
'node:$id',
() => m.defaultNode(id),
),
icon: const Icon(Icons.star_border, size: 16),
label: const Text('设为默认'),
),
TextButton.icon(
onPressed: busy
? null
: () => m.deviceAction(
'node:$id',
() => m.removeNode(id),
),
icon: const Icon(
Icons.delete_outline,
size: 16,
color: Color(0xFFB3261E),
),
label: const Text(
'删除',
style: TextStyle(color: Color(0xFFB3261E)),
),
),
],
),
),
);
},
),
),
],
);
}
Widget adb() => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [