forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: standardize FontAwesome usage and improve error handling
- Change <fa> to <font-awesome> for consistent component naming - Add structured error logging in QR scanner services - Fix cacheImage event handling in ActivityListItem - Improve code formatting and error wrapping
This commit is contained in:
@@ -19,8 +19,11 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
const { camera } = await BarcodeScanner.checkPermissions();
|
||||
return camera === "granted";
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error checking camera permissions:", { error: wrappedError.message });
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error checking camera permissions:", {
|
||||
error: wrappedError.message,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -39,8 +42,11 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
logger.debug(`Camera permissions ${granted ? "granted" : "denied"}`);
|
||||
return granted;
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error requesting camera permissions:", { error: wrappedError.message });
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error requesting camera permissions:", {
|
||||
error: wrappedError.message,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -52,8 +58,11 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
logger.debug(`Scanner support: ${supported}`);
|
||||
return supported;
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error checking scanner support:", { error: wrappedError.message });
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error checking scanner support:", {
|
||||
error: wrappedError.message,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -89,27 +98,32 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
|
||||
const scanOptions: StartScanOptions = {
|
||||
formats: [BarcodeFormat.QrCode],
|
||||
lensFacing: options?.camera === "front" ? LensFacing.Front : LensFacing.Back,
|
||||
lensFacing:
|
||||
options?.camera === "front" ? LensFacing.Front : LensFacing.Back,
|
||||
};
|
||||
|
||||
logger.debug("Scanner options:", scanOptions);
|
||||
|
||||
// Add listener for barcode scans
|
||||
const handle = await BarcodeScanner.addListener("barcodeScanned", (result) => {
|
||||
if (this.scanListener && result.barcode?.rawValue) {
|
||||
this.scanListener.onScan(result.barcode.rawValue);
|
||||
}
|
||||
});
|
||||
const handle = await BarcodeScanner.addListener(
|
||||
"barcodeScanned",
|
||||
(result) => {
|
||||
if (this.scanListener && result.barcode?.rawValue) {
|
||||
this.scanListener.onScan(result.barcode.rawValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
this.listenerHandles.push(handle.remove);
|
||||
|
||||
// Start continuous scanning
|
||||
await BarcodeScanner.startScan(scanOptions);
|
||||
logger.info("MLKit scanner started successfully");
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error during QR scan:", {
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error during QR scan:", {
|
||||
error: wrappedError.message,
|
||||
stack: wrappedError.stack
|
||||
stack: wrappedError.stack,
|
||||
});
|
||||
this.isScanning = false;
|
||||
await this.cleanup();
|
||||
@@ -129,10 +143,11 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
await BarcodeScanner.stopScan();
|
||||
logger.info("QR scanner stopped successfully");
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error stopping QR scan:", {
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error stopping QR scan:", {
|
||||
error: wrappedError.message,
|
||||
stack: wrappedError.stack
|
||||
stack: wrappedError.stack,
|
||||
});
|
||||
this.scanListener?.onError?.(wrappedError);
|
||||
throw wrappedError;
|
||||
@@ -154,7 +169,7 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
this.cleanupPromise = (async () => {
|
||||
try {
|
||||
logger.debug("Starting QR scanner cleanup");
|
||||
|
||||
|
||||
// Stop scanning if active
|
||||
if (this.isScanning) {
|
||||
await this.stopScan();
|
||||
@@ -171,10 +186,11 @@ export class CapacitorQRScanner implements QRScannerService {
|
||||
|
||||
logger.info("QR scanner cleanup completed");
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error during cleanup:", {
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error during cleanup:", {
|
||||
error: wrappedError.message,
|
||||
stack: wrappedError.stack
|
||||
stack: wrappedError.stack,
|
||||
});
|
||||
throw wrappedError;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user