fix: move _aiFallbackExhausted reset out of stopScanner

stopScanner() is called internally by initScanner() on every restart,
so resetting the flag there caused the AI timer to re-arm on every
internal cycle — creating an infinite 5-second loop.

Flag now resets only in showPage('scan'), which fires exclusively when
the user opens the scanner page (fresh session). Internal stop/restart
cycles leave the flag untouched.
This commit is contained in:
dadaloop82
2026-05-29 17:46:45 +00:00
parent b1bcf9e714
commit fd039d743e
+4 -2
View File
@@ -3886,7 +3886,7 @@ function showPage(pageId, param = null) {
} }
loadInventory(); loadInventory();
break; break;
case 'scan': initScanner(); clearQuickNameResults(); updateSpesaBanner(); updateScanRecents(); switchScanTab('barcode'); case 'scan': _aiFallbackExhausted = false; initScanner(); clearQuickNameResults(); updateSpesaBanner(); updateScanRecents(); switchScanTab('barcode');
// Pre-warm the embedding model the first time user visits scan page // Pre-warm the embedding model the first time user visits scan page
if (typeof window._getCategoryPipeline === 'function' && !window._categoryPipelineReady) { if (typeof window._getCategoryPipeline === 'function' && !window._categoryPipelineReady) {
window._getCategoryPipeline(); // fire-and-forget window._getCategoryPipeline(); // fire-and-forget
@@ -6951,7 +6951,9 @@ function stopScanner() {
_scanZoomLevel = 2; // always 2x on next start _scanZoomLevel = 2; // always 2x on next start
_torchActive = false; _torchActive = false;
clearTimeout(_aiFallbackTimer); _aiFallbackTimer = null; clearTimeout(_aiFallbackTimer); _aiFallbackTimer = null;
_aiFallbackExhausted = false; // reset so a new scanner session can try again // NOTE: _aiFallbackExhausted is intentionally NOT reset here.
// It is only reset in showPage('scan') so that internal stop/restart
// cycles (e.g. initScanner calling stopScanner) don't re-arm the AI timer.
if (scannerStream) { if (scannerStream) {
scannerStream.getTracks().forEach(t => t.stop()); scannerStream.getTracks().forEach(t => t.stop());
scannerStream = null; scannerStream = null;