Skip to content

Commit

Permalink
Fixes #9 : remove button if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
clawfire committed Jun 25, 2021
1 parent ba7bc12 commit 0f827b8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ window.addEventListener('load', function() {
function initScanner() {
QrScanner.WORKER_PATH = "/qr-scanner-worker.min.js";
//QrScanner.hasCamera().then(function() {
const flashlight_btn = document.getElementsByClassName('button')[0];
const flashlight_btn = document.getElementsByClassName('button')[1];
// we select the video element, which will provide the user feedback
const video = document.getElementById('scanner');

Expand All @@ -114,11 +114,25 @@ window.addEventListener('load', function() {
// we start scanning
scanner.start().then(() => {
scanner.hasFlash().then(hasFlash => {
if (process.env.NODE_ENV === 'development') {
console.group("\u{1F4A1} Testing flash support")
}
if (hasFlash) {
if (process.env.NODE_ENV === 'development') {
console.log("This device support it");
}
flashlight_btn.classList.remove('disabled')
flashlight_btn.addEventListener('click', () => {
scanner.toggleFlash();
})
} else {
if (process.env.NODE_ENV === 'development') {
console.log("This device don't support it");
}
flashlight_btn.remove();
}
if (process.env.NODE_ENV === 'development') {
console.groupEnd()
}
});
})
Expand Down

0 comments on commit 0f827b8

Please sign in to comment.