|
@ -19,8 +19,11 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
const { camera } = await BarcodeScanner.checkPermissions(); |
|
|
const { camera } = await BarcodeScanner.checkPermissions(); |
|
|
return camera === "granted"; |
|
|
return camera === "granted"; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
const wrappedError = error instanceof Error ? error : new Error(String(error)); |
|
|
const wrappedError = |
|
|
logger.error("Error checking camera permissions:", { error: wrappedError.message }); |
|
|
error instanceof Error ? error : new Error(String(error)); |
|
|
|
|
|
logger.error("Error checking camera permissions:", { |
|
|
|
|
|
error: wrappedError.message, |
|
|
|
|
|
}); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -39,8 +42,11 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
logger.debug(`Camera permissions ${granted ? "granted" : "denied"}`); |
|
|
logger.debug(`Camera permissions ${granted ? "granted" : "denied"}`); |
|
|
return granted; |
|
|
return granted; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
const wrappedError = error instanceof Error ? error : new Error(String(error)); |
|
|
const wrappedError = |
|
|
logger.error("Error requesting camera permissions:", { error: wrappedError.message }); |
|
|
error instanceof Error ? error : new Error(String(error)); |
|
|
|
|
|
logger.error("Error requesting camera permissions:", { |
|
|
|
|
|
error: wrappedError.message, |
|
|
|
|
|
}); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -52,8 +58,11 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
logger.debug(`Scanner support: ${supported}`); |
|
|
logger.debug(`Scanner support: ${supported}`); |
|
|
return supported; |
|
|
return supported; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
const wrappedError = error instanceof Error ? error : new Error(String(error)); |
|
|
const wrappedError = |
|
|
logger.error("Error checking scanner support:", { error: wrappedError.message }); |
|
|
error instanceof Error ? error : new Error(String(error)); |
|
|
|
|
|
logger.error("Error checking scanner support:", { |
|
|
|
|
|
error: wrappedError.message, |
|
|
|
|
|
}); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -89,27 +98,32 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
|
|
|
|
|
|
const scanOptions: StartScanOptions = { |
|
|
const scanOptions: StartScanOptions = { |
|
|
formats: [BarcodeFormat.QrCode], |
|
|
formats: [BarcodeFormat.QrCode], |
|
|
lensFacing: options?.camera === "front" ? LensFacing.Front : LensFacing.Back, |
|
|
lensFacing: |
|
|
|
|
|
options?.camera === "front" ? LensFacing.Front : LensFacing.Back, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
logger.debug("Scanner options:", scanOptions); |
|
|
logger.debug("Scanner options:", scanOptions); |
|
|
|
|
|
|
|
|
// Add listener for barcode scans
|
|
|
// Add listener for barcode scans
|
|
|
const handle = await BarcodeScanner.addListener("barcodeScanned", (result) => { |
|
|
const handle = await BarcodeScanner.addListener( |
|
|
if (this.scanListener && result.barcode?.rawValue) { |
|
|
"barcodeScanned", |
|
|
this.scanListener.onScan(result.barcode.rawValue); |
|
|
(result) => { |
|
|
} |
|
|
if (this.scanListener && result.barcode?.rawValue) { |
|
|
}); |
|
|
this.scanListener.onScan(result.barcode.rawValue); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
this.listenerHandles.push(handle.remove); |
|
|
this.listenerHandles.push(handle.remove); |
|
|
|
|
|
|
|
|
// Start continuous scanning
|
|
|
// Start continuous scanning
|
|
|
await BarcodeScanner.startScan(scanOptions); |
|
|
await BarcodeScanner.startScan(scanOptions); |
|
|
logger.info("MLKit scanner started successfully"); |
|
|
logger.info("MLKit scanner started successfully"); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
const wrappedError = error instanceof Error ? error : new Error(String(error)); |
|
|
const wrappedError = |
|
|
logger.error("Error during QR scan:", { |
|
|
error instanceof Error ? error : new Error(String(error)); |
|
|
|
|
|
logger.error("Error during QR scan:", { |
|
|
error: wrappedError.message, |
|
|
error: wrappedError.message, |
|
|
stack: wrappedError.stack |
|
|
stack: wrappedError.stack, |
|
|
}); |
|
|
}); |
|
|
this.isScanning = false; |
|
|
this.isScanning = false; |
|
|
await this.cleanup(); |
|
|
await this.cleanup(); |
|
@ -129,10 +143,11 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
await BarcodeScanner.stopScan(); |
|
|
await BarcodeScanner.stopScan(); |
|
|
logger.info("QR scanner stopped successfully"); |
|
|
logger.info("QR scanner stopped successfully"); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
const wrappedError = error instanceof Error ? error : new Error(String(error)); |
|
|
const wrappedError = |
|
|
logger.error("Error stopping QR scan:", { |
|
|
error instanceof Error ? error : new Error(String(error)); |
|
|
|
|
|
logger.error("Error stopping QR scan:", { |
|
|
error: wrappedError.message, |
|
|
error: wrappedError.message, |
|
|
stack: wrappedError.stack |
|
|
stack: wrappedError.stack, |
|
|
}); |
|
|
}); |
|
|
this.scanListener?.onError?.(wrappedError); |
|
|
this.scanListener?.onError?.(wrappedError); |
|
|
throw wrappedError; |
|
|
throw wrappedError; |
|
@ -154,7 +169,7 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
this.cleanupPromise = (async () => { |
|
|
this.cleanupPromise = (async () => { |
|
|
try { |
|
|
try { |
|
|
logger.debug("Starting QR scanner cleanup"); |
|
|
logger.debug("Starting QR scanner cleanup"); |
|
|
|
|
|
|
|
|
// Stop scanning if active
|
|
|
// Stop scanning if active
|
|
|
if (this.isScanning) { |
|
|
if (this.isScanning) { |
|
|
await this.stopScan(); |
|
|
await this.stopScan(); |
|
@ -171,10 +186,11 @@ export class CapacitorQRScanner implements QRScannerService { |
|
|
|
|
|
|
|
|
logger.info("QR scanner cleanup completed"); |
|
|
logger.info("QR scanner cleanup completed"); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
const wrappedError = error instanceof Error ? error : new Error(String(error)); |
|
|
const wrappedError = |
|
|
logger.error("Error during cleanup:", { |
|
|
error instanceof Error ? error : new Error(String(error)); |
|
|
|
|
|
logger.error("Error during cleanup:", { |
|
|
error: wrappedError.message, |
|
|
error: wrappedError.message, |
|
|
stack: wrappedError.stack |
|
|
stack: wrappedError.stack, |
|
|
}); |
|
|
}); |
|
|
throw wrappedError; |
|
|
throw wrappedError; |
|
|
} finally { |
|
|
} finally { |
|
|