Skip to content

Commit

Permalink
Revert "Removed baarcode scanner inbox, as we now have enough perform…
Browse files Browse the repository at this point in the history
…ance to apply the decoder to the full image"

This reverts commit de0832b.
  • Loading branch information
jbtronics committed Jan 5, 2025
1 parent 25c8660 commit 4421917
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assets/controllers/pages/barcode_scan_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,29 @@ export default class extends Controller {
connect() {
console.log('Init Scanner');

//This function ensures, that the qrbox is 70% of the total viewport
let qrboxFunction = function(viewfinderWidth, viewfinderHeight) {
let minEdgePercentage = 0.7; // 70%
let minEdgeSize = Math.min(viewfinderWidth, viewfinderHeight);
let qrboxSize = Math.floor(minEdgeSize * minEdgePercentage);
return {
width: qrboxSize,
height: qrboxSize
};
}

//Try to get the number of cameras. If the number is 0, then the promise will fail, and we show the warning dialog
Html5Qrcode.getCameras().catch((devices) => {
document.getElementById('scanner-warning').classList.remove('d-none');
});

this._scanner = new Html5QrcodeScanner(this.element.id, {
fps: 10,
qrbox: qrboxFunction,
experimentalFeatures: {
//This option improves reading quality on android chrome
useBarCodeDetectorIfSupported: true
}
}, false);

this._scanner.render(this.onScanSuccess.bind(this));
Expand Down

0 comments on commit 4421917

Please sign in to comment.