Skip to content

Commit

Permalink
Merge pull request #1182 from siiky/fix/lam-1133/gm-scanner
Browse files Browse the repository at this point in the history
LAM-1133 fix: GM `.then()` arguments
  • Loading branch information
RafaelTaranto authored Sep 12, 2024
2 parents 3ed7616 + 350a183 commit 61d8e52
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/scanner-genmega.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function config (_configuration) {

function cancel () {
if (gmrunning) {
gmrunning = false
genmega.BCSCancelScan()
} else {
scanner.cancel()
Expand All @@ -27,38 +28,37 @@ const isOpened = () => gmrunning || scanner.isOpened()

function scanPDF417 (callback) {
gmrunning = true
return genmega.BCSScan(barcodeScannerPath, 1)
.then((code, data) => {
genmega.BCSScan(barcodeScannerPath, 1)
.then(({ iRet, code }) => {
gmrunning = false
if (code < 0) return callback(new Error(returnValuesTable[code]))
if (iRet < 0 && iRet !== -5) return callback(new Error(returnValuesTable[iRet]))
if (iRet === -5 || !code) return callback(null, null)

if (!data) return callback(null, null)

const parsed = Pdf417Parser.parse(data)
const parsed = Pdf417Parser.parse(code)
if (!parsed) return callback(null, null)
parsed.raw = data
parsed.raw = code
callback(null, parsed)
})
}

function scanPairingCode (shouldSaveAttempt, callback) {
gmrunning = true
return genmega.BCSScan(barcodeScannerPath, 1)
.then((code, data) => {
genmega.BCSScan(barcodeScannerPath, 1)
.then(({ iRet, code }) => {
gmrunning = false
if (code < 0) return callback(new Error(returnValuesTable[code]))
if (!data) data = null
return callback(null, data)
if (iRet < 0 && iRet !== -5) return callback(new Error(returnValuesTable[iRet]))
if (iRet === -5 || !code) code = null
return callback(null, code)
})
}

function scanMainQR (cryptoCode, shouldSaveAttempt, callback) {
gmrunning = true
return genmega.BCSScan(barcodeScannerPath, 1)
.then(({ iRet, code}) => {
genmega.BCSScan(barcodeScannerPath, 1)
.then(({ iRet, code }) => {
gmrunning = false
if (iRet < 0) return callback(new Error(returnValuesTable[iRet]))

if (iRet < 0 && iRet !== -5) return callback(new Error(returnValuesTable[iRet]))
if (iRet === -5) return callback(null, null)
if (!code) {
console.log('scanner: Empty response from genmega lib', code)
return callback(null, null)
Expand All @@ -71,17 +71,17 @@ function scanMainQR (cryptoCode, shouldSaveAttempt, callback) {

function scanPK (callback) {
gmrunning = true
return genmega.BCSScan(barcodeScannerPath, 0)
.then((code, data) => {
genmega.BCSScan(barcodeScannerPath, 0)
.then(({ iRet, code }) => {
gmrunning = false
if (code < 0) return callback(new Error(returnValuesTable[code]))
if (!data) data = null
callback(null, data)
if (iRet < 0 && iRet !== -5) return callback(new Error(returnValuesTable[iRet]))
if (iRet === -5 || !code) code = null
callback(null, code)
})
}

function scanPhotoCard (callback) {
return callback(new Error('ID Card photo is not supported for genmega!'))
callback(new Error('ID Card photo is not supported for genmega!'))
}

module.exports = {
Expand Down

0 comments on commit 61d8e52

Please sign in to comment.