diff --git a/frontend/src/pages/TimeClockPage.jsx b/frontend/src/pages/TimeClockPage.jsx index 537f4c2..f3fc682 100644 --- a/frontend/src/pages/TimeClockPage.jsx +++ b/frontend/src/pages/TimeClockPage.jsx @@ -136,6 +136,47 @@ const TimeClockPage = () => { useEffect(() => () => stopScanner(), []); + useEffect(() => { + if (!isScanning || !videoRef.current) return undefined; + + let cancelled = false; + const reader = new BrowserQRCodeReader(); + + const startReader = async () => { + try { + const controls = await reader.decodeFromConstraints( + { video: { facingMode: { ideal: 'environment' } }, audio: false }, + videoRef.current, + (result) => { + if (result && !cancelled) { + setScanResult(result.getText()); + stopScanner(); + } + }, + ); + + if (cancelled) { + controls.stop(); + } else { + qrControlsRef.current = controls; + } + } catch (scannerError) { + if (!cancelled) { + setError('Impossible d’accéder à la caméra. Vérifiez les permissions et utilisez HTTPS sur le réseau.'); + console.error(scannerError); + stopScanner(); + } + } + }; + + startReader(); + + return () => { + cancelled = true; + reader.reset(); + }; + }, [isScanning]); + const startScanner = async () => { setError(''); setScanResult(''); @@ -152,17 +193,6 @@ const TimeClockPage = () => { } setIsScanning(true); - const reader = new BrowserQRCodeReader(); - qrControlsRef.current = await reader.decodeFromConstraints( - { video: { facingMode: { ideal: 'environment' } }, audio: false }, - videoRef.current, - (result) => { - if (result) { - setScanResult(result.getText()); - stopScanner(); - } - }, - ); } catch (scannerError) { setError('Impossible d’accéder à la caméra. Vérifiez les permissions et utilisez HTTPS sur le réseau.'); console.error(scannerError); diff --git a/start.sh b/start.sh index 464c179..0928459 100644 --- a/start.sh +++ b/start.sh @@ -49,10 +49,8 @@ BACKEND_PID=$! cd /home/container/frontend -if [ ! -x "node_modules/.bin/vite" ]; then - echo "node_modules absent → installation npm..." - npm ci -fi +echo "Installation des dépendances frontend..." +npm ci echo "Build React..."