feat(sender): 设备指纹固定、/watch 实时刷新、中继连接与文件子协议上传

- 新增 PinStore:首次连接记录被控端签名指纹,变化时弹窗确认
- 新增 SignalingWatch:订阅 /watch,300ms 去抖后重拉设备列表
- 设置页新增"连接走信令中继",主控端按该开关走 ttstd_relay_start
- 中继模式禁用投屏并提示原因,状态卡区分直连/中继
- 新增 ControlFileClient:通过 msgType=7 分片上传/列目录,文件页加入口
- NativeCore/Bridge 暴露 relayStart/relayStop/sendFileRequest
This commit is contained in:
tongtong committed 2026-11-27 18:44:49 +08:00
1 parent 22bac28914
commit a9ba4bb7bc
9 files changed
+752 -8

No files matched your search

@@ -2,11 +2,13 @@ import 'dart:io';
import 'package:flutter/material.dart';
import '../../core/control_file_client.dart';
import '../../core/file_client.dart';
/// 浏览 / 下载 / 上传被控端文件。
///
/// 走被控端内置的 LocalSend 风格 HTTP 服务(默认 53317),与串流控制通道互不影响。
/// 默认走被控端内置的 LocalSend 风格 HTTP 服务(默认 53317);控制通道可用时,
/// 还可以用 `msg_type=7` 文件子协议上传(HTTP 端口被防火墙拦掉时的兜底)。
class FileBrowserPage extends StatefulWidget {
const FileBrowserPage({
super.key,
@@ -14,12 +16,16 @@ class FileBrowserPage extends StatefulWidget {
required this.initialPort,
required this.initialToken,
this.onConfigChanged,
this.controlChannel,
});
final String host;
final int initialPort;
final String initialToken;
/// 控制通道文件客户端;为 null 表示当前没有可用控制通道。
final ControlFileClient? controlChannel;
/// 用户改了地址/端口/令牌并保存时通知主界面写回设置。
final void Function(String host, int port, String token)? onConfigChanged;
@@ -226,6 +232,74 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
}
}
/// 走控制通道(`msg_type=7`)上传:HTTP 文件服务不可用时的兜底。
///
/// 文件落在被控端应用私有目录 `file-inbox`,因此这里只提示保存名,
/// 不再刷新 HTTP 目录列表(那棵树看不到这个目录)。
Future<void> _uploadViaControlChannel() async {
final client = widget.controlChannel;
if (client == null) {
_toast('控制通道不可用:请先连接被控端', error: true);
return;
}
final controller = TextEditingController();
final localPath = await showDialog<String>(
context: context,
builder: (dialogContext) => AlertDialog(
title: const Text('通过控制通道上传'),
content: TextField(
controller: controller,
autofocus: true,
decoration: const InputDecoration(
labelText: '本地文件绝对路径',
hintText: r'C:\Users\me\Pictures\a.jpg',
),
),
actions: [
TextButton(onPressed: () => Navigator.pop(dialogContext), child: const Text('取消')),
FilledButton(
onPressed: () => Navigator.pop(dialogContext, controller.text.trim()),
child: const Text('上传'),
),
],
),
);
controller.dispose();
if (localPath == null || localPath.isEmpty) return;
setState(() {
_progress = 0;
_progressLabel = '控制通道上传 ${localPath.split(Platform.pathSeparator).last}';
});
try {
final remote = await client.upload(
localPath,
onProgress: (sent, total) {
if (!mounted) return;
setState(() {
_progress = total > 0 ? sent / total : null;
_progressLabel = '上传中 · ${_size(sent)} / ${_size(total)}';
});
},
);
if (!mounted) return;
_toast('已通过控制通道上传:$remote(被控端 file-inbox)');
} on ControlFileException catch (error) {
if (!mounted) return;
_toast(error.message, error: true);
} on Object catch (error) {
if (!mounted) return;
_toast('控制通道上传失败:$error', error: true);
} finally {
if (mounted) {
setState(() {
_progress = null;
_progressLabel = '';
});
}
}
}
void _saveConfig() {
final host = _hostController.text.trim();
final port = int.tryParse(_portController.text.trim()) ?? _port;
@@ -277,6 +351,11 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
onPressed: directory == null || _loading ? null : _upload,
icon: const Icon(Icons.upload_file),
),
IconButton(
tooltip: '通过控制通道上传(HTTP 不可用时)',
onPressed: _loading ? null : _uploadViaControlChannel,
icon: const Icon(Icons.swap_vert),
),
],
),
body: Column(