Skip to content

fix(scan): guard QR scanning on unsupported devices#48

Merged
qiin2333 merged 1 commit into
masterfrom
codex/pc-scan-capability-guard
Jun 22, 2026
Merged

fix(scan): guard QR scanning on unsupported devices#48
qiin2333 merged 1 commit into
masterfrom
codex/pc-scan-capability-guard

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • QrShareService 里用 SystemCapability.Multimedia.Scan.ScanBarcode 判断当前设备是否支持系统扫码 UI。
  • PC/2in1 等不支持 ScanBarcode 的设备不再显示首页右上角扫码入口,也不会再硬拉 ScanKit 然后弹“扫码取消或失败”。
  • 自定义按键导入面板也做了同样保护,不能扫码的设备会保留剪贴板导入路径。

为啥要改

  • 审核在 MateBook Pro / HarmonyOS 6.1.0 / API23 上点击首页二维码后没有拉起扫码环境,直接显示扫码失败。
  • SDK 设备能力表里 2in1 只有 Scan.CoreGenerateBarcode,没有 ScanBarcode,这个入口在 PC 上本来就是个会摔倒的小杂鱼状态。

验证

  • git diff --check -- entry/src/main/ets/components/CustomKeyOverlay.ets entry/src/main/ets/components/PcListTitleBar.ets entry/src/main/ets/pages/PcListPageV2.ets entry/src/main/ets/service/network/QrShareService.ets
  • DEVECO_SDK_HOME=/Applications/DevEco-Studio.app/Contents/sdk JAVA_HOME=/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home PATH=/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home/bin:$PATH node hvigorw.js assembleHap --no-daemon --stacktrace
  • 产物:entry/build/default/outputs/default/entry-default-unsigned.hap
  • 未做模拟器 UI 回归:hdc list targets -v 只有 127.0.0.1:5555 TCP Offline localhost,当前没有在线设备/模拟器。

回归建议

  • 手机/平板确认扫码按钮仍显示,并可拉起扫码导入/配对。
  • PC/2in1 确认首页右上角扫码入口隐藏,扫描网络和手动添加仍可用。

Summary by CodeRabbit

发布说明

  • 新功能
    • 新增设备QR码扫描能力检测,在应用启动时自动识别当前设备是否支持扫码功能。
    • 不支持扫码的设备会自动提示并回退至剪贴板导入方式。
    • 根据设备能力动态控制扫码导入入口的显示状态。

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c91789a6-4f3a-42c2-827e-1fdf323cd87e

📥 Commits

Reviewing files that changed from the base of the PR and between cbc746d and 0f72af9.

📒 Files selected for processing (4)
  • entry/src/main/ets/components/CustomKeyOverlay.ets
  • entry/src/main/ets/components/PcListTitleBar.ets
  • entry/src/main/ets/pages/PcListPageV2.ets
  • entry/src/main/ets/service/network/QrShareService.ets

📝 Walkthrough

Walkthrough

QrShareService 中新增 syscap 常量与两个静态方法用于系统扫码能力检测,scanQrCode() 本身也增加前置返回保护。PcListTitleBar 的配置接口新增 showScanImport 开关,按钮改为条件渲染。PcListPageV2CustomKeyOverlay 分别消费该检测结果,初始化状态字段并在扫码入口及说明文案处做条件控制。

Changes

扫码能力检测与 UI 条件渲染

Layer / File(s) Summary
QrShareService 能力检测 API
entry/src/main/ets/service/network/QrShareService.ets
新增 SystemCapability.Multimedia.Scan.ScanBarcode 常量与不支持提示文案;新增 isScanQrCodeSupported()canIUse 调用,异常兜底 false)和 getScanUnsupportedMessage()scanQrCode() 开头增加不支持时直接返回 null 的前置判断。
PcListTitleBar 配置扩展与条件渲染
entry/src/main/ets/components/PcListTitleBar.ets
TitleBarConfig 新增可选字段 showScanImport?: boolean,默认 config 补充 showScanImport: truebuild() 中扫码导入按钮改为 showScanImport !== false 时才渲染。
PcListPageV2 状态初始化与扫码前置保护
entry/src/main/ets/pages/PcListPageV2.ets
新增 @State canScanQrCode,在 aboutToAppear() 调用 isScanQrCodeSupported() 初始化;标题栏配置传入 showScanImport: this.canScanQrCodescanAndImportKeys() 增加前置分支在不支持时弹出提示并提前返回。
CustomKeyOverlay 扫码状态与面板 UI 条件渲染
entry/src/main/ets/components/CustomKeyOverlay.ets
新增 canScanQrCode 状态并在 aboutToAppear 初始化;scanAndImport() 增加前置保护;分享面板中扫码导入按钮改为条件渲染;说明文案根据 canScanQrCode 在两种提示间切换。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确总结了主要变更:为不支持的设备添加二维码扫码防护机制,与所有改动文件的核心目标完全对应。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/pc-scan-capability-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qiin2333 qiin2333 merged commit c5d3a99 into master Jun 22, 2026
2 checks passed
@qiin2333 qiin2333 deleted the codex/pc-scan-capability-guard branch June 22, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant