feat: scan the pairing QR code with the camera
The pairing dialog gained a "扫码" button: a full-screen scanner points the back camera at the QR that OpenChamber's connect-a-device dialog shows, and a decoded pairing link connects straight away. Frames are decoded with zxing2 (pure Dart, no ML Kit or Play services): the YUV420 Y plane is already luminance, BGRA frames are converted green-weighted, and each frame is decoded in a background isolate so camera frames never block the UI. Only an openchamber://connect payload ends the scan; any other QR code shows a short hint and scanning continues. A torch button, a denied-permission message with retry, and camera-less devices are handled. The recorder audio permission the camera plugin declares for video is removed from the merged manifest: the scanner reads frames only. 0.4.5 (405).
This commit is contained in:
1 parent
902f1e18bb
commit
8f6fd99103
10 files changed
+634
-13
No files matched your search
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import '../state.dart';
|
||||
import '../storage.dart';
|
||||
import 'scan_qr_screen.dart';
|
||||
|
||||
/// The first screen: the saved servers, or the connect form.
|
||||
class ServersScreen extends StatefulWidget {
|
||||
@@ -420,6 +421,15 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _scan() async {
|
||||
final text = await scanPairingQr(context);
|
||||
if (!mounted || text == null) return;
|
||||
setState(() => _text.text = text);
|
||||
// A scan is an explicit "connect these": do not make the person press
|
||||
// another button after pointing the camera at the code.
|
||||
await _connect();
|
||||
}
|
||||
|
||||
Future<void> _paste() async {
|
||||
final data = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
final text = data?.text?.trim() ?? '';
|
||||
@@ -459,7 +469,7 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'在 OpenChamber 网页端打开「连接设备」,把生成的链接粘贴到这里。'
|
||||
'在 OpenChamber 网页端打开「连接设备」,粘贴链接或直接扫描二维码。'
|
||||
'链接里带一次性密钥,以及直连地址或私有 Relay。',
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
),
|
||||
@@ -482,13 +492,20 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
child: Text(_error!,
|
||||
style: TextStyle(color: theme.colorScheme.error, fontSize: 12.5)),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: _busy ? null : _paste,
|
||||
icon: const Icon(Icons.content_paste, size: 18),
|
||||
label: const Text('从剪贴板粘贴'),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: _busy ? null : _scan,
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 18),
|
||||
label: const Text('扫码'),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
TextButton.icon(
|
||||
onPressed: _busy ? null : _paste,
|
||||
icon: const Icon(Icons.content_paste, size: 18),
|
||||
label: const Text('粘贴'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user