Skip to content

Commit

Permalink
fix: PDF471 codes on desktop Mac (#466)
Browse files Browse the repository at this point in the history
The native BarcodeDetector implementation on desktop Mac seems to
support PDF417 codes but when scanning (always?) returns an empty
string. Thus, now falling back to polyfill under these conditions.

Closes: #459
  • Loading branch information
gruhn authored Feb 11, 2025
1 parent cc200c4 commit bb75c99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/misc/scanner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type DetectedBarcode, type BarcodeFormat, BarcodeDetector, type BarcodeDetectorOptions } from 'barcode-detector/pure'
import { eventOn } from './callforth'
import { DropImageFetchError } from './errors'
import { isMac } from './util'

declare global {
interface Window {
Expand Down Expand Up @@ -48,6 +49,12 @@ async function createBarcodeDetector(formats: BarcodeFormat[]): Promise<BarcodeD
return new BarcodeDetector({ formats })
}

if (isMac() && formats.includes('pdf417')) {
// See: #459
console.debug(`[vue-qrcode-reader] Native BarcodeDetector is buggy for PDF417 codes on MacOS. Will use polyfill.`)
return new BarcodeDetector({ formats })
}

console.debug('[vue-qrcode-reader] Will use native BarcodeDetector.')
return new window.BarcodeDetector({ formats })
}
Expand Down
7 changes: 7 additions & 0 deletions src/misc/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ export function assert(condition: boolean, failureMessage?: string): asserts con
export function assertNever(_witness: never): never {
throw new Error('this code should be unreachable')
}

/**
* Returns true iff the users operating system is desktop MacOS.
*/
export function isMac(): boolean {
return navigator.platform.toUpperCase().includes('MAC')
}

0 comments on commit bb75c99

Please sign in to comment.