Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): scanning of small QR codes #3946

Merged
merged 4 commits into from
Oct 15, 2024
Merged

Conversation

AlCalzone
Copy link
Member

https://github.com/nimiq/qr-scanner uses the native BarcodeDetector if available in browsers (essentially only Chrome), otherwise defaults to a JS port of ZXing. That port seems to be suboptimal, since it really struggles with the small Z-Wave QR codes.

https://www.npmjs.com/package/barcode-detector is a polyfill based on the WASM version of ZXing, which works much, much better. I was able to scan a tiny, blurry, distorted QR code in a second, without having to select "small QR code", or aiming a lot.

We need to decide how to include the wasm module though, since we don't want to download it at runtime, see https://github.com/Sec-ant/barcode-detector?tab=readme-ov-file#setzxingmoduleoverrides

@coveralls
Copy link

coveralls commented Oct 12, 2024

Pull Request Test Coverage Report for Build 11344607116

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 21.021%

Totals Coverage Status
Change from base Build 11341592356: 0.0%
Covered Lines: 3925
Relevant Lines: 19852

💛 - Coveralls

@robertsLando
Copy link
Member

robertsLando commented Oct 14, 2024

@AlCalzone You mean this?

// src/index.ts
import wasmFile from "../node_modules/zxing-wasm/dist/reader/zxing_reader.wasm?url";

import {
  setZXingModuleOverrides,
  BarcodeDetector,
} from "barcode-detector/pure";

setZXingModuleOverrides({
  locateFile: (path, prefix) => {
    if (path.endsWith(".wasm")) {
      return wasmFile;
    }
    return prefix + path;
  },
});

const barcodeDetector = new BarcodeDetector();

// detect barcodes
// ...

@AlCalzone
Copy link
Member Author

Yes, minus the const barcodeDetector = ...

@robertsLando robertsLando marked this pull request as ready for review October 15, 2024 10:00
Comment on lines 140 to 141
import { setZXingModuleOverrides } from 'barcode-detector/pure'
import 'barcode-detector/side-effects'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { setZXingModuleOverrides } from 'barcode-detector/pure'
import 'barcode-detector/side-effects'
import { setZXingModuleOverrides } from 'barcode-detector'

should work as well

@robertsLando robertsLando changed the title fix: scanning of small QR codes fix(ui): scanning of small QR codes Oct 15, 2024
@robertsLando robertsLando merged commit 6420ee4 into master Oct 15, 2024
9 checks passed
@robertsLando robertsLando deleted the fix-QR-code-scanning branch October 15, 2024 13:30
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.

3 participants