chore: cleanup and test

This commit is contained in:
Matthew Raymer
2025-04-22 07:48:04 +00:00
parent 448f32abaa
commit 3e87b2ecda
9 changed files with 75 additions and 49 deletions

View File

@@ -54,9 +54,9 @@ export class CapacitorQRScanner implements QRScannerService {
try {
// Ensure we have permissions before starting
logger.log('Checking camera permissions...');
logger.log("Checking camera permissions...");
if (!(await this.checkPermissions())) {
logger.log('Requesting camera permissions...');
logger.log("Requesting camera permissions...");
const granted = await this.requestPermissions();
if (!granted) {
throw new Error("Camera permission denied");
@@ -64,12 +64,12 @@ export class CapacitorQRScanner implements QRScannerService {
}
// Check if scanning is supported
logger.log('Checking scanner support...');
logger.log("Checking scanner support...");
if (!(await this.isSupported())) {
throw new Error("QR scanning not supported on this device");
}
logger.log('Starting MLKit scanner...');
logger.log("Starting MLKit scanner...");
this.isScanning = true;
const scanOptions: StartScanOptions = {
@@ -78,9 +78,9 @@ export class CapacitorQRScanner implements QRScannerService {
options?.camera === "front" ? LensFacing.Front : LensFacing.Back,
};
logger.log('Scanner options:', scanOptions);
logger.log("Scanner options:", scanOptions);
const result = await BarcodeScanner.scan(scanOptions);
logger.log('Scan result:', result);
logger.log("Scan result:", result);
if (result.barcodes.length > 0) {
this.scanListener?.onScan(result.barcodes[0].rawValue);

View File

@@ -14,16 +14,16 @@ export class QRScannerFactory {
const capacitorNative = Capacitor.isNativePlatform();
const isMobile = __IS_MOBILE__;
const platform = Capacitor.getPlatform();
logger.log('Platform detection:', {
logger.log("Platform detection:", {
capacitorNative,
isMobile,
platform,
userAgent: navigator.userAgent
userAgent: navigator.userAgent,
});
// Force native scanner on Android/iOS
if (platform === 'android' || platform === 'ios') {
if (platform === "android" || platform === "ios") {
return true;
}
@@ -36,16 +36,20 @@ export class QRScannerFactory {
static getInstance(): QRScannerService {
if (!this.instance) {
const isNative = this.isNativePlatform();
logger.log(`Creating QR scanner for platform: ${isNative ? 'native' : 'web'}`);
logger.log(
`Creating QR scanner for platform: ${isNative ? "native" : "web"}`,
);
if (isNative) {
logger.log('Using native MLKit scanner');
logger.log("Using native MLKit scanner");
this.instance = new CapacitorQRScanner();
} else if (__USE_QR_READER__) {
logger.log('Using web QR scanner');
logger.log("Using web QR scanner");
this.instance = new WebDialogQRScanner();
} else {
throw new Error("No QR scanner implementation available for this platform");
throw new Error(
"No QR scanner implementation available for this platform",
);
}
}
return this.instance!; // We know it's not null here

View File

@@ -318,12 +318,12 @@ export class CapacitorPlatformService implements PlatformService {
async writeAndShareFile(fileName: string, content: string): Promise<void> {
const timestamp = new Date().toISOString();
const logData = {
action: 'writeAndShareFile',
action: "writeAndShareFile",
fileName,
contentLength: content.length,
timestamp,
};
logger.log('[CapacitorPlatformService]', JSON.stringify(logData, null, 2));
logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2));
try {
const { uri } = await Filesystem.writeFile({
@@ -334,13 +334,16 @@ export class CapacitorPlatformService implements PlatformService {
recursive: true,
});
logger.log('[CapacitorPlatformService] File write successful:', { uri, timestamp: new Date().toISOString() });
logger.log("[CapacitorPlatformService] File write successful:", {
uri,
timestamp: new Date().toISOString(),
});
await Share.share({
title: 'TimeSafari Backup',
text: 'Here is your backup file.',
title: "TimeSafari Backup",
text: "Here is your backup file.",
url: uri,
dialogTitle: 'Share your backup file',
dialogTitle: "Share your backup file",
});
} catch (error) {
const err = error as Error;
@@ -349,7 +352,10 @@ export class CapacitorPlatformService implements PlatformService {
stack: err.stack,
timestamp: new Date().toISOString(),
};
logger.error('[CapacitorPlatformService] Error writing or sharing file:', JSON.stringify(errLog, null, 2));
logger.error(
"[CapacitorPlatformService] Error writing or sharing file:",
JSON.stringify(errLog, null, 2),
);
throw new Error(`Failed to write or share file: ${err.message}`);
}
}