fix: QR 扫描失败 + GUI 导出失败 — PNG margin + separator + fs 插件

🔴 QR 扫描失败根因 (2项):
- render/png: saturating_sub 导致 margin 区域映射到 finder 黑角,
  quiet zone 全黑,扫描器无法定位 QR
- matrix/patterns: 缺少右上 finder 左侧 + 左下 finder 顶部
  隔离带预留,数据模块破坏 finder 检测比率(1:1:3:1:1)

🔴 GUI 导出失败 (2项):
- gui/Cargo.toml + gui/lib.rs: 注册 tauri-plugin-fs 后端插件
  (前端 writeFile 调用缺少 Rust handler)
- capabilities: fs:allow-write-file + $HOME/** 路径 scope
  (ACL 默认不给 fs 写权限,需显式声明)

🔧 其他:
- ExportPanel: 导出失败显示红色错误信息(替代静默吞错)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-18 11:21:27 +08:00
parent 1e9c94eff9
commit 05b1714628
14 changed files with 7210 additions and 16 deletions
+13 -3
View File
@@ -24,13 +24,23 @@ pub fn place_finder_patterns(matrix: &mut Matrix) {
matrix.reserve(x, y);
}
}
// 定位图案分隔符(1 模块宽的白色边框,在 finder 周
// 定位图案分隔符(1 模块宽的白色边框,在 finder 周)
for i in 0..8u8 {
// 右侧分隔列(finder 右边缘外侧)
if fx + 7 < matrix.size {
matrix.reserve(fx + 7, fy + i); // 右侧分隔列
matrix.reserve(fx + 7, fy + i);
}
// 底部隔行(finder 下边缘外侧)
if fy + 7 < matrix.size {
matrix.reserve(fx + i, fy + 7); // 底部隔行
matrix.reserve(fx + i, fy + 7);
}
// 左侧分隔列(finder 左边缘外侧,非左边界时有效)
if fx > 0 {
matrix.reserve(fx - 1, fy + i);
}
// 顶部隔行(finder 上边缘外侧,非上边界时有效)
if fy > 0 {
matrix.reserve(fx + i, fy - 1);
}
}
}
+10 -6
View File
@@ -29,13 +29,17 @@ pub fn render_png(qr: &QrCode, module_size: u8) -> Result<Vec<u8>, image::ImageE
for y in 0..total_size {
for x in 0..total_size {
let module_x = x.saturating_sub(margin);
let module_y = y.saturating_sub(margin);
let is_dark = if module_x < matrix_size && module_y < matrix_size {
qr.modules()[module_y as usize][module_x as usize]
// 直接比较坐标与 margin 边界,避免 saturating_sub 在边界处回绕到 0
let is_dark = if x >= margin
&& x < margin + matrix_size
&& y >= margin
&& y < margin + matrix_size
{
let mx = (x - margin) as usize;
let my = (y - margin) as usize;
qr.modules()[my][mx]
} else {
false // 白边
false // 白边 (quiet zone)
};
fill_module(&mut img, x, y, module_size as u32, is_dark);