From d4986e9f5b4dcf736ba463eb7947ad7432680691 Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Thu, 10 Oct 2024 16:37:48 -0400 Subject: [PATCH] prevent barcode scanner plugin from being invoked if it is already open testing done: double-tapped "scan code" multiple trials and observed no errors. The scanner successfully opened on each trial --- www/js/onboarding/WelcomePage.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/www/js/onboarding/WelcomePage.tsx b/www/js/onboarding/WelcomePage.tsx index 7ded3a208..87a0a3778 100644 --- a/www/js/onboarding/WelcomePage.tsx +++ b/www/js/onboarding/WelcomePage.tsx @@ -26,6 +26,9 @@ import { initByUser } from '../config/dynamicConfig'; import { AppContext } from '../App'; import { displayError, logDebug } from '../plugin/logger'; import { onboardingStyles } from './OnboardingStack'; +import { AlertManager } from '../components/AlertBar'; + +let barcodeScannerIsOpen = false; const WelcomePage = () => { const { t } = useTranslation(); @@ -57,8 +60,11 @@ const WelcomePage = () => { } function scanCode() { + if (barcodeScannerIsOpen) return; + barcodeScannerIsOpen = true; window['cordova'].plugins.barcodeScanner.scan( (result) => { + barcodeScannerIsOpen = false; logDebug('scanCode: scanned ' + JSON.stringify(result)); let code = getCode(result); if (code != false) { @@ -69,7 +75,8 @@ const WelcomePage = () => { } }, (error) => { - displayError(error, 'Scanning failed: '); + barcodeScannerIsOpen = false; + AlertManager.addMessage({ text: 'Scanning failed: ' + error.message }); }, ); }