fix(sender): 串流窗口锁定视频比例,关窗即停流,修正文件传输取 IP
- 独立窗口首帧到达后按视频宽高比自动调整并居中;WM_SIZING 锁定比例,最小 320x180 - 去掉 WS_MAXIMIZEBOX 与双击/F11 全屏,只保留关闭与最小化 - 移除停止投屏按钮;WM_DESTROY 通过 ttstd/video 通道回调 windowClosed,Dart 侧下发 stopMirror - 文件传输地址优先取设备局域网 IP,取不到时回退控制通道 peerIp,并在文件页提供可编辑 IP 输入
This commit is contained in:
1 parent
d3ff293877
commit
d8357a8491
8 files changed
+321
-127
No files matched your search
@@ -20,19 +20,22 @@ class FileBrowserPage extends StatefulWidget {
|
||||
final int initialPort;
|
||||
final String initialToken;
|
||||
|
||||
/// 用户改了端口/令牌并保存时通知主界面写回设置。
|
||||
final void Function(int port, String token)? onConfigChanged;
|
||||
/// 用户改了地址/端口/令牌并保存时通知主界面写回设置。
|
||||
final void Function(String host, int port, String token)? onConfigChanged;
|
||||
|
||||
@override
|
||||
State<FileBrowserPage> createState() => _FileBrowserPageState();
|
||||
}
|
||||
|
||||
class _FileBrowserPageState extends State<FileBrowserPage> {
|
||||
late final TextEditingController _hostController =
|
||||
TextEditingController(text: widget.host);
|
||||
late final TextEditingController _portController =
|
||||
TextEditingController(text: widget.initialPort.toString());
|
||||
late final TextEditingController _tokenController =
|
||||
TextEditingController(text: widget.initialToken);
|
||||
|
||||
late String _host = widget.host;
|
||||
late int _port = widget.initialPort;
|
||||
late String _token = widget.initialToken;
|
||||
|
||||
@@ -58,15 +61,15 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
|
||||
}
|
||||
|
||||
Future<void> _connect() async {
|
||||
if (widget.host.isEmpty) {
|
||||
setState(() => _error = '还没有选中设备,请先连接被控端');
|
||||
if (_host.isEmpty || _host == '127.0.0.1') {
|
||||
setState(() => _error = '还没有拿到被控端的局域网 IP,请在上方「IP」里手动填写(例如 192.168.1.23)');
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
final client = AndroidFileClient(host: widget.host, port: _port, token: _token);
|
||||
final client = AndroidFileClient(host: _host, port: _port, token: _token);
|
||||
try {
|
||||
final info = await client.info();
|
||||
final directory = await client.browse('');
|
||||
@@ -224,13 +227,15 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
|
||||
}
|
||||
|
||||
void _saveConfig() {
|
||||
final host = _hostController.text.trim();
|
||||
final port = int.tryParse(_portController.text.trim()) ?? _port;
|
||||
final token = _tokenController.text.trim();
|
||||
setState(() {
|
||||
_host = host;
|
||||
_port = port;
|
||||
_token = token;
|
||||
});
|
||||
widget.onConfigChanged?.call(port, token);
|
||||
widget.onConfigChanged?.call(host, port, token);
|
||||
_toast('参数已保存');
|
||||
_connect();
|
||||
}
|
||||
@@ -256,7 +261,7 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(widget.host.isEmpty ? '文件传输' : '${widget.host}:$_port'),
|
||||
Text(_host.isEmpty ? '文件传输' : '$_host:$_port'),
|
||||
if (_alias.isNotEmpty)
|
||||
Text(_alias, style: theme.textTheme.bodySmall),
|
||||
],
|
||||
@@ -306,6 +311,18 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: TextField(
|
||||
controller: _hostController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'IP',
|
||||
hintText: '192.168.1.23',
|
||||
isDense: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _portController,
|
||||
@@ -316,9 +333,12 @@ class _FileBrowserPageState extends State<FileBrowserPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: TextField(
|
||||
controller: _tokenController,
|
||||
decoration: const InputDecoration(
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
||||
|
||||
/// 串流控制卡片。
|
||||
///
|
||||
/// 主界面不渲染投屏画面,画面统一显示在独立原生窗口里;这里只负责
|
||||
/// 「请求投屏 / 停止投屏」与窗口显隐、状态展示。
|
||||
/// 主界面不渲染投屏画面,画面统一显示在独立原生窗口里;窗口尺寸按视频比例自动适配,
|
||||
/// 关闭窗口即停止投屏,所以这里只保留「请求投屏」一个动作。
|
||||
class MirrorBar extends StatelessWidget {
|
||||
const MirrorBar({
|
||||
super.key,
|
||||
@@ -15,8 +15,6 @@ class MirrorBar extends StatelessWidget {
|
||||
required this.frames,
|
||||
required this.error,
|
||||
required this.onRequest,
|
||||
required this.onStop,
|
||||
required this.onToggleWindow,
|
||||
});
|
||||
|
||||
final bool connected;
|
||||
@@ -28,13 +26,10 @@ class MirrorBar extends StatelessWidget {
|
||||
final String error;
|
||||
|
||||
final VoidCallback onRequest;
|
||||
final VoidCallback onStop;
|
||||
final VoidCallback onToggleWindow;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final status = _statusText();
|
||||
final statusColor = _statusColor(theme);
|
||||
|
||||
return Card(
|
||||
@@ -57,17 +52,13 @@ class MirrorBar extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
status,
|
||||
_statusText(),
|
||||
style: theme.textTheme.labelSmall?.copyWith(color: statusColor),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (windowOpen)
|
||||
IconButton(
|
||||
tooltip: '显示/隐藏串流窗口',
|
||||
onPressed: onToggleWindow,
|
||||
icon: const Icon(Icons.picture_in_picture_alt),
|
||||
),
|
||||
Text('串流窗口已打开', style: theme.textTheme.labelSmall),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
@@ -78,24 +69,15 @@ class MirrorBar extends StatelessWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: FilledButton.icon(
|
||||
onPressed: connected && !busy ? onRequest : null,
|
||||
icon: const Icon(Icons.play_circle_outline),
|
||||
label: const Text('请求投屏'),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton.icon(
|
||||
onPressed: connected && !busy && !streaming ? onRequest : null,
|
||||
icon: Icon(
|
||||
streaming ? Icons.cast_connected : Icons.play_circle_outline,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: onStop,
|
||||
icon: const Icon(Icons.stop_circle_outlined),
|
||||
label: const Text('停止投屏'),
|
||||
),
|
||||
),
|
||||
],
|
||||
label: Text(streaming ? '投屏中 · 关闭窗口即停止' : '请求投屏'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -124,9 +106,9 @@ class MirrorBar extends StatelessWidget {
|
||||
if (!connected) return '先在上方连接被控端,再请求投屏';
|
||||
if (streaming) {
|
||||
final size = resolution.isEmpty ? '未知分辨率' : resolution;
|
||||
return '$size · 已接收 $frames 帧 · 画面在独立窗口显示';
|
||||
return '$size · 已接收 $frames 帧 · 关闭独立窗口会立即停止投屏';
|
||||
}
|
||||
if (windowOpen) return '已向被控端发送投屏请求,请在其弹窗中点击「允许」';
|
||||
return '点击「请求投屏」后会弹出独立窗口播放画面';
|
||||
return '点击「请求投屏」会按视频比例弹出独立窗口播放画面';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user