From 652ee3892ef3e61d2928e0465e8158558415aaf7 Mon Sep 17 00:00:00 2001 From: Michael Neuendorf Date: Sun, 29 Mar 2020 13:30:29 +0200 Subject: [PATCH] Add feature to always turn on the torch in camera scanner. --- config-dist.php | 1 + public/viewjs/components/barcodescanner.js | 29 ++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/config-dist.php b/config-dist.php index f6da7527..82ae183e 100644 --- a/config-dist.php +++ b/config-dist.php @@ -154,3 +154,4 @@ Setting('FEATURE_FLAG_CHORES_ASSIGNMENTS', true); # Feature settings Setting('FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT', true); // When set to false, opened products will not be considered for minimum stock amounts +Setting('FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA', true); // Enables the torch automaticaly in every camera barcode scanner. diff --git a/public/viewjs/components/barcodescanner.js b/public/viewjs/components/barcodescanner.js index 855eba8e..e243520e 100644 --- a/public/viewjs/components/barcodescanner.js +++ b/public/viewjs/components/barcodescanner.js @@ -8,10 +8,16 @@ Grocy.Components.BarcodeScanner.CheckCapabilities = function() capabilities = track.getCapabilities(); } + // Check if the camera is capable to turn on a torch. var canTorch = typeof capabilities.torch === 'boolean' && capabilities.torch + // Remove the torch button, if either the device can not torch or AutoTorchOn is set. var node = document.querySelector('.torch'); if (node) { - node.style.display = canTorch ? 'inline-block' : 'none'; + node.style.display = canTorch && !Grocy.FeatureFlags.FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA ? 'inline-block' : 'none'; + } + // If AutoTorchOn is set, turn on the torch. + if (canTorch && Grocy.FeatureFlags.FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA) { + Grocy.Components.BarcodeScanner.TorchOn(track); } // Reduce the height of the video, if it's heigher than then the viewport @@ -116,6 +122,19 @@ Grocy.Components.BarcodeScanner.StopScanning = function() bootbox.hideAll(); } +Grocy.Components.BarcodeScanner.TorchOn = function(track) +{ + if (track) { + track.applyConstraints({ + advanced: [ + { + torch: true + } + ] + }); + } +} + Quagga.onDetected(function(result) { $.each(result.codeResult.decodedCodes, function(id, error) @@ -192,13 +211,7 @@ $(document).on("click", "#barcodescanner-start-button", function(e) className: 'btn-warning responsive-button torch', callback: function() { - Quagga.CameraAccess.getActiveTrack().applyConstraints({ - advanced: [ - { - torch: true - } - ] - }); + Grocy.Components.BarcodeScanner.TorchOn(Quagga.CameraAccess.getActiveTrack()); return false; } },