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(
@@ -30,6 +30,7 @@ class _SettingsPageState extends State<SettingsPage> {
late bool _audioEnabled;
late bool _clipboardSync;
late bool _fileTransfer;
late bool _relayEnabled;
late int _bitrateMbps;
DeviceInfo? _localListener;
ServiceCheckResult? _serviceResult;
@@ -50,6 +51,7 @@ class _SettingsPageState extends State<SettingsPage> {
_audioEnabled = widget.settings.audioEnabled;
_clipboardSync = widget.settings.clipboardSync;
_fileTransfer = widget.settings.fileTransfer;
_relayEnabled = widget.settings.relayEnabled;
_bitrateMbps = widget.settings.bitrateMbps;
_loadLocalListener();
_refreshListenerState();
@@ -180,6 +182,10 @@ class _SettingsPageState extends State<SettingsPage> {
_snack('请填写外部信令服务器地址');
return;
}
if (_relayEnabled && _useLocalSignaling) {
_snack('中继需要被控端也能访问的信令地址,请改用外部信令');
return;
}
if (int.tryParse(_localPort.text.trim()) == null) {
_snack('本机端口必须是数字');
return;
@@ -209,6 +215,7 @@ class _SettingsPageState extends State<SettingsPage> {
audioEnabled: _audioEnabled,
clipboardSync: _clipboardSync,
fileTransfer: _fileTransfer,
relayEnabled: _relayEnabled,
bitrateMbps: _bitrateMbps,
filePort: int.tryParse(_filePort.text.trim()) ?? widget.settings.filePort,
fileToken: _fileToken.text.trim(),
@@ -410,6 +417,12 @@ class _SettingsPageState extends State<SettingsPage> {
value: _fileTransfer,
onChanged: (value) => setState(() => _fileTransfer = value),
),
SwitchListTile(
title: const Text('连接走信令中继'),
subtitle: const Text('跨网段时使用;中继只承载控制通道,不能投屏/传音频'),
value: _relayEnabled,
onChanged: (value) => setState(() => _relayEnabled = value),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
child: Row(