refactor(qr): improve QR code scanning robustness and error handling
- Enhance JWT extraction with unified path handling and validation - Add debouncing to prevent duplicate scans - Improve error handling and logging throughout QR flow - Add proper TypeScript interfaces for QR scan results - Implement mobile app lifecycle handlers (pause/resume) - Enhance logging with structured data and consistent levels - Clean up scanner resources properly on component destroy - Split contact handling into separate method for better organization - Add proper type for UserNameDialog ref This commit improves the reliability and maintainability of the QR code scanning functionality while adding better error handling and logging.
This commit is contained in:
@@ -86,15 +86,18 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
};
|
||||
|
||||
logger.log("Scanner options:", scanOptions);
|
||||
|
||||
|
||||
// Add listener for barcode scans
|
||||
const handle = await BarcodeScanner.addListener('barcodeScanned', (result) => {
|
||||
if (this.scanListener) {
|
||||
this.scanListener.onScan(result.barcode.rawValue);
|
||||
}
|
||||
});
|
||||
const handle = await BarcodeScanner.addListener(
|
||||
"barcodeScanned",
|
||||
(result) => {
|
||||
if (this.scanListener) {
|
||||
this.scanListener.onScan(result.barcode.rawValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
this.listenerHandles.push(handle.remove);
|
||||
|
||||
|
||||
// Start continuous scanning
|
||||
await BarcodeScanner.startScan(scanOptions);
|
||||
} catch (error) {
|
||||
|
||||
@@ -13,13 +13,18 @@ export class QRScannerFactory {
|
||||
private static isNativePlatform(): boolean {
|
||||
// Debug logging for build flags
|
||||
logger.log("Build flags:", {
|
||||
IS_MOBILE: typeof __IS_MOBILE__ !== 'undefined' ? __IS_MOBILE__ : 'undefined',
|
||||
USE_QR_READER: typeof __USE_QR_READER__ !== 'undefined' ? __USE_QR_READER__ : 'undefined',
|
||||
IS_MOBILE:
|
||||
typeof __IS_MOBILE__ !== "undefined" ? __IS_MOBILE__ : "undefined",
|
||||
USE_QR_READER:
|
||||
typeof __USE_QR_READER__ !== "undefined"
|
||||
? __USE_QR_READER__
|
||||
: "undefined",
|
||||
VITE_PLATFORM: process.env.VITE_PLATFORM,
|
||||
});
|
||||
|
||||
const capacitorNative = Capacitor.isNativePlatform();
|
||||
const isMobile = typeof __IS_MOBILE__ !== 'undefined' ? __IS_MOBILE__ : capacitorNative;
|
||||
const isMobile =
|
||||
typeof __IS_MOBILE__ !== "undefined" ? __IS_MOBILE__ : capacitorNative;
|
||||
const platform = Capacitor.getPlatform();
|
||||
|
||||
logger.log("Platform detection:", {
|
||||
@@ -37,7 +42,10 @@ export class QRScannerFactory {
|
||||
|
||||
// For other platforms, use native if available
|
||||
const useNative = capacitorNative || isMobile;
|
||||
logger.log("Platform decision:", { useNative, reason: useNative ? "capacitorNative/isMobile" : "web" });
|
||||
logger.log("Platform decision:", {
|
||||
useNative,
|
||||
reason: useNative ? "capacitorNative/isMobile" : "web",
|
||||
});
|
||||
return useNative;
|
||||
}
|
||||
|
||||
@@ -55,7 +63,11 @@ export class QRScannerFactory {
|
||||
if (isNative) {
|
||||
logger.log("Using native MLKit scanner");
|
||||
this.instance = new CapacitorQRScanner();
|
||||
} else if (typeof __USE_QR_READER__ !== 'undefined' ? __USE_QR_READER__ : !isNative) {
|
||||
} else if (
|
||||
typeof __USE_QR_READER__ !== "undefined"
|
||||
? __USE_QR_READER__
|
||||
: !isNative
|
||||
) {
|
||||
logger.log("Using web QR scanner");
|
||||
this.instance = new WebDialogQRScanner();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user