- Flutter 桌面端通过 dart:ffi 调用 Rust Core cdylib - 实现 ECDH P-256 密钥协商、HKDF 子密钥派生、AES-256-GCM 控制帧 - Android 被控端用派生密钥做控制帧加密与媒体包 MAC - 新增 libopus JNI 骨架,默认回退 MediaCodec - 新增 aosp/zhanxun/neutral 签名变体与系统 sharedUserId - 本机独立信令服务与设置页开关 - 新增 .gitignore 排除所有编译产物与打包目录
255 lines
9.3 KiB
Dart
255 lines
9.3 KiB
Dart
import 'package:flutter/material.dart';
|
||
|
||
import '../../core/bridge.dart';
|
||
import '../../core/models.dart';
|
||
|
||
class SettingsPage extends StatefulWidget {
|
||
const SettingsPage({
|
||
super.key,
|
||
required this.settings,
|
||
required this.bridge,
|
||
});
|
||
|
||
final AppSettings settings;
|
||
final SenderBridge bridge;
|
||
|
||
@override
|
||
State<SettingsPage> createState() => _SettingsPageState();
|
||
}
|
||
|
||
class _SettingsPageState extends State<SettingsPage> {
|
||
late final TextEditingController _signalingUrl;
|
||
late final TextEditingController _localPort;
|
||
late bool _useLocalSignaling;
|
||
late bool _localSignalingEnabled;
|
||
late bool _localRunning;
|
||
late bool _preferH265;
|
||
late bool _audioEnabled;
|
||
late bool _clipboardSync;
|
||
late bool _fileTransfer;
|
||
late int _bitrateMbps;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_signalingUrl = TextEditingController(text: widget.settings.signalingUrl);
|
||
_localPort = TextEditingController(text: '${widget.settings.localSignalingPort}');
|
||
_useLocalSignaling = widget.settings.useLocalSignaling;
|
||
_localSignalingEnabled = widget.settings.localSignalingEnabled;
|
||
_localRunning = widget.bridge.isLocalSignalingRunning;
|
||
_preferH265 = widget.settings.preferH265;
|
||
_audioEnabled = widget.settings.audioEnabled;
|
||
_clipboardSync = widget.settings.clipboardSync;
|
||
_fileTransfer = widget.settings.fileTransfer;
|
||
_bitrateMbps = widget.settings.bitrateMbps;
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_signalingUrl.dispose();
|
||
_localPort.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
int get _port {
|
||
final parsed = int.tryParse(_localPort.text.trim());
|
||
return parsed != null && parsed >= 1 && parsed <= 65535 ? parsed : 8080;
|
||
}
|
||
|
||
void _snack(String message) {
|
||
if (mounted) {
|
||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||
}
|
||
}
|
||
|
||
void _setLocalServer(bool enabled) {
|
||
setState(() => _localSignalingEnabled = enabled);
|
||
}
|
||
|
||
Future<void> _save() async {
|
||
if (!_useLocalSignaling && _signalingUrl.text.trim().isEmpty) {
|
||
_snack('请填写外部信令服务器地址');
|
||
return;
|
||
}
|
||
if (int.tryParse(_localPort.text.trim()) == null) {
|
||
_snack('本机端口必须是数字');
|
||
return;
|
||
}
|
||
|
||
if (_localSignalingEnabled) {
|
||
if (!_localRunning || _port != widget.settings.localSignalingPort) {
|
||
await widget.bridge.stopLocalSignaling();
|
||
final started = await widget.bridge.startLocalSignaling(_port);
|
||
if (!mounted) return;
|
||
setState(() => _localRunning = started);
|
||
if (!started) _snack('本机信令服务启动失败');
|
||
}
|
||
} else if (_localRunning) {
|
||
await widget.bridge.stopLocalSignaling();
|
||
if (!mounted) return;
|
||
setState(() => _localRunning = false);
|
||
}
|
||
|
||
if (!mounted) return;
|
||
Navigator.of(context).pop(AppSettings(
|
||
signalingUrl: _signalingUrl.text.trim(),
|
||
useLocalSignaling: _useLocalSignaling,
|
||
localSignalingEnabled: _localSignalingEnabled,
|
||
localSignalingPort: _port,
|
||
preferH265: _preferH265,
|
||
audioEnabled: _audioEnabled,
|
||
clipboardSync: _clipboardSync,
|
||
fileTransfer: _fileTransfer,
|
||
bitrateMbps: _bitrateMbps,
|
||
));
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final theme = Theme.of(context);
|
||
return Scaffold(
|
||
appBar: AppBar(title: const Text('设置')),
|
||
body: ListView(
|
||
padding: const EdgeInsets.all(16),
|
||
children: [
|
||
Card(
|
||
child: Padding(
|
||
padding: const EdgeInsets.all(12),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Icon(Icons.dns, color: theme.colorScheme.primary),
|
||
const SizedBox(width: 8),
|
||
Text('信令服务器', style: theme.textTheme.titleMedium),
|
||
],
|
||
),
|
||
const SizedBox(height: 8),
|
||
SwitchListTile(
|
||
title: const Text('使用本机信令服务器'),
|
||
subtitle: const Text('默认开启;安装包内置独立 Go 信令服务'),
|
||
value: _useLocalSignaling,
|
||
onChanged: (value) => setState(() => _useLocalSignaling = value),
|
||
),
|
||
if (_useLocalSignaling) ...[
|
||
SwitchListTile(
|
||
title: const Text('开启本机信令服务'),
|
||
subtitle: Text(
|
||
!_localSignalingEnabled
|
||
? '已关闭'
|
||
: (_localRunning ? '服务运行中' : '保存设置后启动'),
|
||
style: TextStyle(
|
||
color: _localSignalingEnabled && _localRunning
|
||
? theme.colorScheme.primary
|
||
: theme.colorScheme.error,
|
||
),
|
||
),
|
||
value: _localSignalingEnabled,
|
||
onChanged: _setLocalServer,
|
||
),
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: TextField(
|
||
controller: _localPort,
|
||
keyboardType: TextInputType.number,
|
||
decoration: const InputDecoration(
|
||
labelText: '本机监听端口',
|
||
hintText: '8080',
|
||
prefixIcon: Icon(Icons.numbers),
|
||
border: OutlineInputBorder(),
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(height: 12),
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: Text(
|
||
'本机地址:${widget.bridge.localSignalingUrl(_port)}\n手机端扫码或手动填写该地址即可注册。',
|
||
style: theme.textTheme.bodySmall,
|
||
),
|
||
),
|
||
if (!_localSignalingEnabled)
|
||
Padding(
|
||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||
child: Text(
|
||
'本机服务已关闭,但当前仍选择“使用本机信令服务器”,设备列表将不可用。',
|
||
style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.error),
|
||
),
|
||
),
|
||
] else ...[
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: TextField(
|
||
controller: _signalingUrl,
|
||
decoration: const InputDecoration(
|
||
labelText: '外部信令服务器',
|
||
hintText: 'http://192.168.1.5:8080',
|
||
prefixIcon: Icon(Icons.cloud),
|
||
border: OutlineInputBorder(),
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(height: 12),
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: Text(
|
||
'跨网段时通过自部署信令服务器交换地址。',
|
||
style: theme.textTheme.bodySmall,
|
||
),
|
||
),
|
||
],
|
||
],
|
||
),
|
||
),
|
||
),
|
||
const Divider(height: 32),
|
||
SwitchListTile(
|
||
title: const Text('优先使用 H.265'),
|
||
subtitle: const Text('带宽更省,要求被控端支持'),
|
||
value: _preferH265,
|
||
onChanged: (value) => setState(() => _preferH265 = value),
|
||
),
|
||
SwitchListTile(
|
||
title: const Text('启用音频'),
|
||
subtitle: const Text('AudioPlaybackCapture / OPUS'),
|
||
value: _audioEnabled,
|
||
onChanged: (value) => setState(() => _audioEnabled = value),
|
||
),
|
||
SwitchListTile(
|
||
title: const Text('剪贴板同步'),
|
||
subtitle: const Text('通过控制通道双向同步文本'),
|
||
value: _clipboardSync,
|
||
onChanged: (value) => setState(() => _clipboardSync = value),
|
||
),
|
||
SwitchListTile(
|
||
title: const Text('允许文件传输'),
|
||
subtitle: const Text('复用 TLS 会话,支持分片续传'),
|
||
value: _fileTransfer,
|
||
onChanged: (value) => setState(() => _fileTransfer = value),
|
||
),
|
||
const Divider(height: 32),
|
||
ListTile(
|
||
title: const Text('投屏码率'),
|
||
subtitle: Text('$_bitrateMbps Mbps · 1080p 建议 6–10 Mbps'),
|
||
),
|
||
Slider(
|
||
min: 2,
|
||
max: 20,
|
||
divisions: 18,
|
||
value: _bitrateMbps.toDouble(),
|
||
label: '$_bitrateMbps Mbps',
|
||
onChanged: (value) => setState(() => _bitrateMbps = value.round()),
|
||
),
|
||
const SizedBox(height: 24),
|
||
FilledButton.icon(
|
||
onPressed: _save,
|
||
icon: const Icon(Icons.save),
|
||
label: const Text('保存设置'),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|