fix direct pairing probe timeout and speed up QR scanning

This commit is contained in:
zhy200308
2026-08-12 11:26:59 +08:00
parent f9e25819ee
commit eccd93266e
6 changed files with 111 additions and 24 deletions
+6
View File
@@ -1109,6 +1109,9 @@ impl QftApp {
self.receive.direct_ap = direct_ap;
self.receive.events = Some(rx);
self.receive.pair_texture = Some(ctx.load_texture("qft-pair-code", image, TextureOptions::NEAREST));
// 扫码是启动后的唯一下一步,默认把窗口让给大二维码;用户仍可退出
// 专注模式查看防火墙、地址和接收状态。
self.receive.focus_qr = true;
self.receive.session_token = token;
self.receive.connected_device = "等待 Android 扫码".into();
self.receive.current_file = "—".into();
@@ -1190,6 +1193,9 @@ impl QftApp {
self.send.direct_ap = direct_ap;
self.send.events = Some(rx);
self.send.pair_texture = Some(ctx.load_texture("qft-send-code", image, TextureOptions::NEAREST));
// QFTSEND2 往往还带文件名、大小和 SHA-256,比接收码更密;生成后
// 直接放大显示,避免控制区把模块压到手机相机的识别下限附近。
self.send.qr_focus = true;
self.send.session_token = token;
self.send.connected_device = "等待 Android 扫码".into();
self.send.status = if self.send.use_direct_ap {
+15 -2
View File
@@ -3,6 +3,7 @@ use eframe::egui::ColorImage;
use qrcode::{types::Color, EcLevel, QrCode};
const QUIET_MODULES: usize = 4;
const PAIR_EC_LEVEL: EcLevel = EcLevel::L;
/// Active optical renderer. QFT2/Base45 text uses only QR alphanumeric
/// characters, allowing the QR encoder to choose a compact alphanumeric data
@@ -16,9 +17,11 @@ pub fn render_qr_fitted(text: &str, target_side: usize) -> Result<ColorImage> {
Ok(ColorImage::from_gray([side, side], &render_code_gray(&code, side)))
}
/// Pairing QR stays static and uses M error correction for first-scan reliability.
/// Pairing happens from a clean, static desktop display. QR-L keeps long
/// QFTSEND2 payloads several versions smaller than QR-M, giving the camera
/// materially more pixels per module; the full quiet zone remains intact.
pub fn render_pair_qr(text: &str, target_side: usize) -> Result<ColorImage> {
let code = QrCode::with_error_correction_level(text.as_bytes(), EcLevel::M)
let code = QrCode::with_error_correction_level(text.as_bytes(), PAIR_EC_LEVEL)
.context("pair QR payload too large")?;
let modules = code.width() + QUIET_MODULES * 2;
let scale = (target_side / modules).max(1);
@@ -26,6 +29,16 @@ pub fn render_pair_qr(text: &str, target_side: usize) -> Result<ColorImage> {
Ok(ColorImage::from_gray([side, side], &render_code_gray(&code, side)))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn pairing_qr_uses_low_density_error_correction() {
assert_eq!(PAIR_EC_LEVEL, EcLevel::L);
}
}
fn render_code_gray(code: &QrCode, side: usize) -> Vec<u8> {
let qr_width = code.width();
let modules = qr_width + QUIET_MODULES * 2;