forked from jsnbuchanan/crowd-funder-for-time-pwa
fix(qr): add retry logic to QR scanner initialization
- Retries QR scanner initialization up to 3 times if it fails, with a delay between attempts - Improves user experience on slow or delayed camera hardware/browser permission responses - Updates status message to reflect retry attempts
This commit is contained in:
@@ -273,7 +273,7 @@ export default class QRScannerDialog extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onInit(promise: Promise<void>): Promise<void> {
|
async onInit(promise: Promise<void>, attempt = 1): Promise<void> {
|
||||||
if (this.isNativePlatform) {
|
if (this.isNativePlatform) {
|
||||||
logger.log("Skipping web scanner initialization on native platform");
|
logger.log("Skipping web scanner initialization on native platform");
|
||||||
return;
|
return;
|
||||||
@@ -350,12 +350,17 @@ export default class QRScannerDialog extends Vue {
|
|||||||
// Now initialize the QR scanner
|
// Now initialize the QR scanner
|
||||||
this.initializationStatus = "Starting QR scanner...";
|
this.initializationStatus = "Starting QR scanner...";
|
||||||
logger.log("Initializing QR scanner...");
|
logger.log("Initializing QR scanner...");
|
||||||
// await promise; // <-- comment this out for debugging
|
await promise;
|
||||||
|
|
||||||
this.isInitializing = false;
|
this.isInitializing = false;
|
||||||
this.cameraStatus = "Ready";
|
this.cameraStatus = "Ready";
|
||||||
logger.log("QR scanner initialized successfully");
|
logger.log("QR scanner initialized successfully");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (attempt < 3) {
|
||||||
|
// Retry after a short delay
|
||||||
|
setTimeout(() => this.onInit(promise, attempt + 1), 1500);
|
||||||
|
this.initializationStatus = `Retrying camera initialization (attempt ${attempt + 1})...`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
const wrappedError =
|
const wrappedError =
|
||||||
error instanceof Error ? error : new Error(String(error));
|
error instanceof Error ? error : new Error(String(error));
|
||||||
this.error = wrappedError.message;
|
this.error = wrappedError.message;
|
||||||
|
|||||||
Reference in New Issue
Block a user