- 支持 Ctrl+V 粘贴配对文本和二维码图片,预览确认后识别校验 - 修复控制发送阻塞、TLS 读写争锁、设备切换沿用旧连接及串流误关窗 - 优化媒体加密上下文、UDP 接收缓冲和异步诊断日志 - 安装器按路径停止主控与信令进程,统一递增版本、打包和清理旧产物 - 发布 0.1.3+4,通过三端编译、20 项 Flutter 测试和 58 项 Rust 单元测试
137 lines
4.8 KiB
Dart
137 lines
4.8 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../core/pairing.dart';
|
|
import '../../core/pairing_input.dart';
|
|
|
|
class PairingPasteDialog extends StatefulWidget {
|
|
const PairingPasteDialog(
|
|
{super.key, this.readClipboard = readPairingClipboard, this.decodeImage});
|
|
final Future<PairingClipboardContent> Function() readClipboard;
|
|
final Future<PairingUri> Function(Uint8List)? decodeImage;
|
|
|
|
@override
|
|
State<PairingPasteDialog> createState() => _PairingPasteDialogState();
|
|
}
|
|
|
|
class _PairingPasteDialogState extends State<PairingPasteDialog> {
|
|
PairingClipboardContent? _content;
|
|
bool _busy = false;
|
|
String? _error;
|
|
|
|
Future<void> _paste() async {
|
|
if (_busy) return;
|
|
setState(() {
|
|
_busy = true;
|
|
_error = null;
|
|
});
|
|
try {
|
|
final content = await widget.readClipboard();
|
|
if (mounted) setState(() => _content = content);
|
|
} on Object catch (error) {
|
|
if (mounted)
|
|
setState(() {
|
|
_content = null;
|
|
_error = _message(error);
|
|
});
|
|
} finally {
|
|
if (mounted) setState(() => _busy = false);
|
|
}
|
|
}
|
|
|
|
String _message(Object error) =>
|
|
error is FormatException ? error.message : '读取或识别失败,请重新复制后重试';
|
|
|
|
Future<void> _confirm() async {
|
|
final content = _content;
|
|
if (_busy || content == null) return;
|
|
setState(() {
|
|
_busy = true;
|
|
_error = null;
|
|
});
|
|
try {
|
|
final image = content.image;
|
|
final PairingUri pairing;
|
|
if (image != null) {
|
|
pairing = await (widget.decodeImage?.call(image) ??
|
|
compute(parsePairingImage, image));
|
|
} else {
|
|
pairing = parsePairingText(content.text ?? '');
|
|
}
|
|
if (mounted) Navigator.of(context).pop(pairing);
|
|
} on Object catch (error) {
|
|
if (mounted) setState(() => _error = _message(error));
|
|
} finally {
|
|
if (mounted) setState(() => _busy = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final image = _content?.image;
|
|
return CallbackShortcuts(
|
|
bindings: {
|
|
const SingleActivator(LogicalKeyboardKey.keyV, control: true): _paste,
|
|
const SingleActivator(LogicalKeyboardKey.keyV, meta: true): _paste,
|
|
},
|
|
child: Focus(
|
|
autofocus: true,
|
|
child: AlertDialog(
|
|
title: const Text('扫码配对'),
|
|
content: SizedBox(
|
|
width: 480,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Text('按 Ctrl+V 粘贴配对文本或二维码图片。核对预览后,点击确认配对进行识别和校验。'),
|
|
const SizedBox(height: 16),
|
|
Container(
|
|
constraints:
|
|
const BoxConstraints(minHeight: 140, maxHeight: 260),
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: image == null ? null : Colors.white,
|
|
border: Border.all(
|
|
color: Theme.of(context).colorScheme.outline),
|
|
borderRadius: BorderRadius.circular(8)),
|
|
child: image != null
|
|
? Image.memory(image,
|
|
fit: BoxFit.contain,
|
|
cacheWidth: 640,
|
|
errorBuilder: (_, __, ___) =>
|
|
const Text('图片预览不可用,可点击确认尝试识别或重新粘贴'))
|
|
: SingleChildScrollView(
|
|
child: Text(_content?.text ?? '等待粘贴…')),
|
|
),
|
|
if (_error != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 12),
|
|
child: Text(_error!,
|
|
style: TextStyle(
|
|
color: Theme.of(context).colorScheme.error))),
|
|
if (_busy)
|
|
const Padding(
|
|
padding: EdgeInsets.only(top: 12),
|
|
child: LinearProgressIndicator()),
|
|
]),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: _busy ? null : () => Navigator.of(context).pop(),
|
|
child: const Text('取消')),
|
|
TextButton(
|
|
onPressed: _busy ? null : _paste, child: const Text('粘贴')),
|
|
FilledButton(
|
|
onPressed: _busy || _content == null ? null : _confirm,
|
|
child: const Text('确认配对')),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|