Skip to content

Commit

Permalink
Merge pull request #1186 from JGreenlee/debounce-barcodescanner
Browse files Browse the repository at this point in the history
prevent barcode scanner plugin from being invoked if it is already open
  • Loading branch information
shankari authored Oct 11, 2024
2 parents ab90f8a + d4986e9 commit 66f61e0
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;

const WelcomePage = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -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) {
Expand All @@ -69,7 +75,8 @@ const WelcomePage = () => {
}
},
(error) => {
displayError(error, 'Scanning failed: ');
barcodeScannerIsOpen = false;
AlertManager.addMessage({ text: 'Scanning failed: ' + error.message });
},
);
}
Expand Down

0 comments on commit 66f61e0

Please sign in to comment.