Skip to content

Commit

Permalink
prevent barcode scanner plugin from being invoked if it is already open
Browse files Browse the repository at this point in the history
testing done: double-tapped "scan code" multiple trials and observed no errors. The scanner successfully opened on each trial
  • Loading branch information
JGreenlee committed Oct 10, 2024
1 parent ab90f8a commit d4986e9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion www/js/onboarding/WelcomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 31 in www/js/onboarding/WelcomePage.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/onboarding/WelcomePage.tsx#L31

Added line #L31 was not covered by tests

const WelcomePage = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -57,8 +60,11 @@ const WelcomePage = () => {
}

function scanCode() {
if (barcodeScannerIsOpen) return;
barcodeScannerIsOpen = true;

Check warning on line 64 in www/js/onboarding/WelcomePage.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/onboarding/WelcomePage.tsx#L64

Added line #L64 was not covered by tests
window['cordova'].plugins.barcodeScanner.scan(
(result) => {
barcodeScannerIsOpen = false;

Check warning on line 67 in www/js/onboarding/WelcomePage.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/onboarding/WelcomePage.tsx#L67

Added line #L67 was not covered by tests
logDebug('scanCode: scanned ' + JSON.stringify(result));
let code = getCode(result);
if (code != false) {
Expand All @@ -69,7 +75,8 @@ const WelcomePage = () => {
}
},
(error) => {
displayError(error, 'Scanning failed: ');
barcodeScannerIsOpen = false;
AlertManager.addMessage({ text: 'Scanning failed: ' + error.message });

Check warning on line 79 in www/js/onboarding/WelcomePage.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/onboarding/WelcomePage.tsx#L78-L79

Added lines #L78 - L79 were not covered by tests
},
);
}
Expand Down

0 comments on commit d4986e9

Please sign in to comment.