From e897570968ae3444acabd8fe3ef9fee8084a6aa9 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 13 Apr 2020 22:34:52 +0200 Subject: [PATCH] Only adjust the camera barcode scanning live stream picture size once (fixes #734) --- public/viewjs/components/barcodescanner.js | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/public/viewjs/components/barcodescanner.js b/public/viewjs/components/barcodescanner.js index ef313e0a..a9da9db8 100644 --- a/public/viewjs/components/barcodescanner.js +++ b/public/viewjs/components/barcodescanner.js @@ -1,5 +1,6 @@ Grocy.Components.BarcodeScanner = { }; +Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = false; Grocy.Components.BarcodeScanner.CheckCapabilities = async function() { var track = Quagga.CameraAccess.getActiveTrack(); @@ -28,18 +29,26 @@ Grocy.Components.BarcodeScanner.CheckCapabilities = async function() } // Reduce the height of the video, if it's heigher than then the viewport - var bc = document.getElementById('barcodescanner-container'); - if (bc) { - var bcAspectRatio = bc.offsetWidth / bc.offsetHeight; - var settings = track.getSettings(); - if (bcAspectRatio > settings.aspectRatio) { - var v = document.querySelector('#barcodescanner-livestream video') - if (v) { - var c = document.querySelector('#barcodescanner-livestream canvas') - var newWidth = v.clientWidth / bcAspectRatio * settings.aspectRatio + 'px'; - v.style.width = newWidth; - c.style.width = newWidth; + if (!Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted) + { + var bc = document.getElementById('barcodescanner-container'); + if (bc) + { + var bcAspectRatio = bc.offsetWidth / bc.offsetHeight; + var settings = track.getSettings(); + if (bcAspectRatio > settings.aspectRatio) + { + var v = document.querySelector('#barcodescanner-livestream video') + if (v) + { + var c = document.querySelector('#barcodescanner-livestream canvas') + var newWidth = v.clientWidth / bcAspectRatio * settings.aspectRatio + 'px'; + v.style.width = newWidth; + c.style.width = newWidth; + } } + + Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = true; } } }