feat(sender): 首页移除投屏画面,请求投屏直开独立窗口,新增文件传输
- 删除首页 VideoView:画面只在独立原生窗口显示,首页改为状态卡片(分辨率/帧数/错误) - 新增 MirrorBar 卡片,请求投屏/停止投屏从控制工具栏独立出来;点请求即打开独立窗口再下发 msg_type=8 - 停止投屏同时下发 stop 并关闭窗口;控制工具栏移除投屏按钮 - 独立窗口无画面时居中提示「等待被控端画面…」 - 新增 core/file_client.dart 与 file_browser_page:浏览/下载到 Downloads/TTSTD/上传,带进度与错误提示 - AppSettings 增加 filePort/fileToken 并接入设置页与首页文件卡片
This commit is contained in:
1 parent
993097df00
commit
d3ff293877
10 files changed
+1029
-189
No files matched your search
+144
-38
@@ -9,8 +9,9 @@ import 'core/native_core.dart';
|
||||
import 'core/models.dart';
|
||||
import 'features/control/control_toolbar.dart';
|
||||
import 'features/discovery/device_list.dart';
|
||||
import 'features/media/video_view.dart';
|
||||
import 'features/file/file_browser_page.dart';
|
||||
import 'features/session/connect_bar.dart';
|
||||
import 'features/session/mirror_bar.dart';
|
||||
import 'features/settings/settings_page.dart';
|
||||
|
||||
void main() => runApp(const TTSTDConnectApp());
|
||||
@@ -62,6 +63,8 @@ class _HomePageState extends State<HomePage> {
|
||||
int? _textureId;
|
||||
/// 串流画面是否已弹出到独立原生窗口。
|
||||
bool _videoWindowOpen = false;
|
||||
/// 正在拉起窗口并下发投屏请求。
|
||||
bool _mirrorRequesting = false;
|
||||
String? _nativeError;
|
||||
|
||||
@override
|
||||
@@ -167,7 +170,44 @@ class _HomePageState extends State<HomePage> {
|
||||
});
|
||||
}
|
||||
|
||||
/// 把串流画面弹出/收回独立原生窗口(Windows)。
|
||||
/// 请求投屏:先把独立串流窗口打开,再向被控端下发投屏请求。
|
||||
///
|
||||
/// 被控端会弹窗确认,确认后才开始推流;这段时间窗口显示「等待画面」。
|
||||
Future<void> _requestMirror() async {
|
||||
if (!_phase.isConnected) {
|
||||
_snack('请先连接被控端');
|
||||
return;
|
||||
}
|
||||
setState(() => _mirrorRequesting = true);
|
||||
try {
|
||||
if (!_videoWindowOpen) {
|
||||
final opened = await _bridge.openVideoWindow();
|
||||
if (!mounted) return;
|
||||
if (!opened) {
|
||||
_snack('当前平台不支持独立串流窗口');
|
||||
return;
|
||||
}
|
||||
setState(() => _videoWindowOpen = true);
|
||||
}
|
||||
_sendControl('requestMirror', const {});
|
||||
_diagnosticLog.write('mirror request sent');
|
||||
} finally {
|
||||
if (mounted) setState(() => _mirrorRequesting = false);
|
||||
}
|
||||
}
|
||||
|
||||
/// 停止投屏:通知被控端结束推流,并关闭独立画面窗口。
|
||||
Future<void> _stopMirror() async {
|
||||
if (_phase.isConnected) {
|
||||
_sendControl('stopMirror', const {});
|
||||
_diagnosticLog.write('mirror stop sent');
|
||||
}
|
||||
await _bridge.closeVideoWindow();
|
||||
if (!mounted) return;
|
||||
setState(() => _videoWindowOpen = false);
|
||||
}
|
||||
|
||||
/// 独立窗口显隐(不停流)。
|
||||
Future<void> _toggleVideoWindow() async {
|
||||
if (_videoWindowOpen) {
|
||||
await _bridge.closeVideoWindow();
|
||||
@@ -178,14 +218,81 @@ class _HomePageState extends State<HomePage> {
|
||||
final opened = await _bridge.openVideoWindow();
|
||||
if (!mounted) return;
|
||||
if (!opened) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('当前平台不支持独立串流窗口')),
|
||||
);
|
||||
_snack('当前平台不支持独立串流窗口');
|
||||
return;
|
||||
}
|
||||
setState(() => _videoWindowOpen = true);
|
||||
}
|
||||
|
||||
void _snack(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
/// 文件传输入口:浏览 / 下载 / 上传被控端文件。
|
||||
Widget _buildFileTransferCard() {
|
||||
final device = _selected;
|
||||
final host = device?.ip ?? '';
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.folder_shared_outlined, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text('文件传输', style: Theme.of(context).textTheme.titleMedium),
|
||||
const Spacer(),
|
||||
Text(
|
||||
host.isEmpty ? '未选设备' : '$host:${_settings.filePort}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'浏览被控端目录、下载到本机 Downloads/TTSTD,或上传文件到被控端当前目录。'
|
||||
'需要被控端待命服务运行,并填写其主界面显示的文件服务令牌。',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: _settings.fileTransfer ? _openFileBrowser : null,
|
||||
icon: const Icon(Icons.folder_open, size: 18),
|
||||
label: const Text('浏览被控端文件'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openFileBrowser() async {
|
||||
final device = _selected;
|
||||
if (device == null) {
|
||||
_snack('请先选中被控端设备');
|
||||
return;
|
||||
}
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => FileBrowserPage(
|
||||
host: device.ip,
|
||||
initialPort: _settings.filePort,
|
||||
initialToken: _settings.fileToken,
|
||||
onConfigChanged: (port, token) {
|
||||
final updated = _settings.copyWith(filePort: port, fileToken: token);
|
||||
setState(() => _settings = updated);
|
||||
_bridge.saveSettings(updated);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _writeDiagnosticLog() {
|
||||
Map<String, dynamic> status;
|
||||
if (_nativeCore == null) {
|
||||
@@ -341,8 +448,17 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
void _sendControl(String type, Map<String, dynamic> payload) {
|
||||
_bridge.sendControl(type, payload);
|
||||
const labels = {
|
||||
'requestMirror': '投屏请求',
|
||||
'stopMirror': '停止投屏',
|
||||
'clipboard': '剪贴板内容',
|
||||
'ping': '心跳',
|
||||
};
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('已发送 $type 控制事件'), duration: const Duration(milliseconds: 900)),
|
||||
SnackBar(
|
||||
content: Text('已发送${labels[type] ?? ' $type '}'),
|
||||
duration: const Duration(milliseconds: 900),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -352,11 +468,6 @@ class _HomePageState extends State<HomePage> {
|
||||
appBar: AppBar(
|
||||
title: const Text('TTSTD Connect'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: _videoWindowOpen ? '收回串流窗口' : '串流独立窗口',
|
||||
onPressed: _toggleVideoWindow,
|
||||
icon: Icon(_videoWindowOpen ? Icons.close_fullscreen : Icons.open_in_new),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '扫码配对',
|
||||
onPressed: _showPairing,
|
||||
@@ -531,54 +642,49 @@ class _HomePageState extends State<HomePage> {
|
||||
return _selected?.resolution ?? '';
|
||||
}
|
||||
|
||||
int? get _videoPts {
|
||||
final decoded = _videoStats['decoded'];
|
||||
final pts = _videoStats['pts'];
|
||||
if (decoded is int && decoded > 0 && pts is int) return pts;
|
||||
return null;
|
||||
}
|
||||
|
||||
String get _videoError => (_videoStats['error'] as String? ?? '').trim();
|
||||
|
||||
/// 按实际码流宽高算显示比例;竖屏被控端(如 1080x2400)不再被压成 16:9。
|
||||
double get _videoAspectRatio {
|
||||
final width = _videoStats['width'];
|
||||
final height = _videoStats['height'];
|
||||
if (width is int && height is int && width > 0 && height > 0) {
|
||||
return width / height;
|
||||
}
|
||||
return 16 / 9;
|
||||
int get _videoFrames {
|
||||
final decoded = _videoStats['decoded'];
|
||||
return decoded is int ? decoded : 0;
|
||||
}
|
||||
|
||||
/// 是否已经在接收画面(首页不显示画面,只看状态)。
|
||||
bool get _videoStreaming => _videoFrames > 0 && _videoError.isEmpty;
|
||||
|
||||
Widget _buildStage() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
VideoView(
|
||||
// 独立窗口在播时不再占用主窗口纹理。
|
||||
textureId: _videoWindowOpen ? null : _textureId,
|
||||
connected: _phase.isConnected,
|
||||
resolution: _videoResolution,
|
||||
pts: _videoPts,
|
||||
error: _videoError,
|
||||
standalone: _videoWindowOpen,
|
||||
aspectRatio: _videoAspectRatio,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ConnectBar(
|
||||
phase: _phase,
|
||||
device: _selected,
|
||||
onConnect: _connect,
|
||||
onDisconnect: _disconnect,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 12),
|
||||
MirrorBar(
|
||||
connected: _phase.isConnected,
|
||||
streaming: _videoStreaming,
|
||||
windowOpen: _videoWindowOpen,
|
||||
busy: _mirrorRequesting,
|
||||
resolution: _videoResolution,
|
||||
frames: _videoFrames,
|
||||
error: _videoError,
|
||||
onRequest: _requestMirror,
|
||||
onStop: _stopMirror,
|
||||
onToggleWindow: _toggleVideoWindow,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ControlToolbar(
|
||||
enabled: _phase.isConnected,
|
||||
onEvent: _sendControl,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildFileTransferCard(),
|
||||
const SizedBox(height: 12),
|
||||
_buildConnectionStatusCard(),
|
||||
const SizedBox(height: 12),
|
||||
Card(
|
||||
|
||||
Reference in new issue
Block a user