Skip to content

Commit

Permalink
Bug fix, do not log to console from zxing-js if verbose flag is turne…
Browse files Browse the repository at this point in the history
…d off (#178)
  • Loading branch information
mebjas authored Apr 15, 2021
1 parent 1177ca4 commit 2c9c5ef
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version 2.0.1
- **Bug fix**: Zxing-js library was logging to console even if `verbose` is false - https://github.com/mebjas/html5-qrcode/issues/175

### Version 2.0.0
- **Major Change** Migrated from Lazarsoft QR Code scanning to `ZXing-js`.
- More robust support for QR Code scanning
Expand Down
2 changes: 1 addition & 1 deletion minified/html5-qrcode.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html5-qrcode",
"version": "2.0.0",
"version": "2.0.1",
"description": "A cross platform HTML5 QR Code & bar code scanner",
"main": "minified/html5-qrcode.min.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/html5-qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Html5Qrcode {
ZXing.BarcodeFormat.UPC_EAN_EXTENSION,
];
hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, formats);
this.qrcode = new ZXing.MultiFormatReader();
this.qrcode = new ZXing.MultiFormatReader(verbose);
this.qrcode.setHints(hints);

this._elementId = elementId;
Expand Down
42 changes: 30 additions & 12 deletions third_party/zxing-js.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -10228,11 +10228,12 @@
// import java.util.Map;
// import java.util.Collections;
class RSSExpandedReader extends AbstractRSSReader {
constructor() {
constructor(verbose) {
super(...arguments);
this.pairs = new Array(RSSExpandedReader.MAX_PAIRS);
this.rows = new Array();
this.startEnd = [2];
this.verbose = (verbose === true);
}
decodeRow(rowNumber, row, hints) {
// Rows can start with even pattern in case in prev rows there where odd number of patters.
Expand All @@ -10245,7 +10246,9 @@
}
catch (e) {
// OK
console.log(e);
if (this.verbose) {
console.log(e);
}
}
this.pairs.length = 0;
this.startFromEven = true;
Expand Down Expand Up @@ -10319,7 +10322,9 @@
}
catch (e) {
// OK
console.log(e);
if (this.verbose) {
console.log(e);
}
}
if (reverse) {
this.rows = this.rows.reverse();
Expand Down Expand Up @@ -10351,7 +10356,9 @@
}
catch (e) {
// We failed, try the next candidate
console.log(e);
if (this.verbose) {
console.log(e);
}
}
}
throw new NotFoundException();
Expand Down Expand Up @@ -10546,7 +10553,9 @@
}
catch (e) {
rightChar = null;
console.log(e);
if (this.verbose) {
console.log(e);
}
}
return new ExpandedPair(leftChar, rightChar, pattern, true);
}
Expand Down Expand Up @@ -11326,9 +11335,10 @@
* @author Sean Owen
*/
class MultiFormatOneDReader extends OneDReader {
constructor(hints) {
constructor(hints, verbose) {
super();
this.readers = [];
this.verbose = (verbose === true);
const possibleFormats = !hints ? null : hints.get(DecodeHintType$1.POSSIBLE_FORMATS);
const useCode39CheckDigit = hints && hints.get(DecodeHintType$1.ASSUME_CODE_39_CHECK_DIGIT) !== undefined;
if (possibleFormats) {
Expand Down Expand Up @@ -11357,7 +11367,7 @@
this.readers.push(new RSS14Reader());
}
if (possibleFormats.includes(BarcodeFormat$1.RSS_EXPANDED)) {
this.readers.push(new RSSExpandedReader());
this.readers.push(new RSSExpandedReader(this.verbose));
}
}
if (this.readers.length === 0) {
Expand All @@ -11369,7 +11379,7 @@
this.readers.push(new Code128Reader());
this.readers.push(new ITFReader());
this.readers.push(new RSS14Reader());
this.readers.push(new RSSExpandedReader());
this.readers.push(new RSSExpandedReader(this.verbose));
}
}
// @Override
Expand Down Expand Up @@ -20688,6 +20698,14 @@
* @author [email protected] (Daniel Switkin)
*/
class MultiFormatReader {
/**
* Creates an instance of this class
*
* @param {Boolean} verbose if 'true' logs will be dumped to console, otherwise hidden.
*/
constructor(verbose) {
this.verbose = (verbose === true);
}
/**
* This version of decode honors the intent of Reader.decode(BinaryBitmap) in that it
* passes null as a hint to the decoders. However, that makes it inefficient to call repeatedly.
Expand Down Expand Up @@ -20761,7 +20779,7 @@
// Put 1D readers upfront in "normal" mode
// TYPESCRIPTPORT: TODO: uncomment below as they are ported
if (addOneDReader && !tryHarder) {
readers.push(new MultiFormatOneDReader(hints));
readers.push(new MultiFormatOneDReader(hints, this.verbose));
}
if (formats.includes(BarcodeFormat$1.QR_CODE)) {
readers.push(new QRCodeReader());
Expand All @@ -20780,20 +20798,20 @@
// }
// At end in "try harder" mode
if (addOneDReader && tryHarder) {
readers.push(new MultiFormatOneDReader(hints));
readers.push(new MultiFormatOneDReader(hints, this.verbose));
}
}
if (readers.length === 0) {
if (!tryHarder) {
readers.push(new MultiFormatOneDReader(hints));
readers.push(new MultiFormatOneDReader(hints, this.verbose));
}
readers.push(new QRCodeReader());
readers.push(new DataMatrixReader());
readers.push(new AztecReader());
readers.push(new PDF417Reader());
// readers.push(new MaxiCodeReader())
if (tryHarder) {
readers.push(new MultiFormatOneDReader(hints));
readers.push(new MultiFormatOneDReader(hints, this.verbose));
}
}
this.readers = readers; // .toArray(new Reader[readers.size()])
Expand Down
2 changes: 1 addition & 1 deletion third_party/zxing-js.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion transpiled/html5-qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var Html5Qrcode = /*#__PURE__*/function () {
var hints = new Map();
var formats = [ZXing.BarcodeFormat.QR_CODE, ZXing.BarcodeFormat.AZTEC, ZXing.BarcodeFormat.CODABAR, ZXing.BarcodeFormat.CODE_39, ZXing.BarcodeFormat.CODE_93, ZXing.BarcodeFormat.CODE_128, ZXing.BarcodeFormat.DATA_MATRIX, ZXing.BarcodeFormat.MAXICODE, ZXing.BarcodeFormat.ITF, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.PDF_417, ZXing.BarcodeFormat.RSS_14, ZXing.BarcodeFormat.RSS_EXPANDED, ZXing.BarcodeFormat.UPC_A, ZXing.BarcodeFormat.UPC_E, ZXing.BarcodeFormat.UPC_EAN_EXTENSION];
hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, formats);
this.qrcode = new ZXing.MultiFormatReader();
this.qrcode = new ZXing.MultiFormatReader(verbose);
this.qrcode.setHints(hints);
this._elementId = elementId;
this._foreverScanTimeout = null;
Expand Down

0 comments on commit 2c9c5ef

Please sign in to comment.