Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent barcode scanner plugin from being invoked if it is already open #1186

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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 @@
}

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 @@
}
},
(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
Loading