From a93694728ead07f9c40a5aa1e8e0cb23fe0977a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=BCllner?= Date: Wed, 4 Mar 2026 11:08:03 +0100 Subject: [PATCH] chore(scanner): add duplicate-ID cooldown for rapid scan stability - Ignore repeated processing of the same HW ID within a short 2s window - Prevent duplicate dialogs/inserts during very fast repeated captures - Keep continuous scanner loop responsive while reducing accidental re-triggers --- lib/screens/scan_tab.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/screens/scan_tab.dart b/lib/screens/scan_tab.dart index a675d9f..cbbc557 100644 --- a/lib/screens/scan_tab.dart +++ b/lib/screens/scan_tab.dart @@ -14,11 +14,14 @@ class ScanTab extends StatefulWidget { class ScanTabState extends State { static const _activeCollectionPrefKey = 'active_collection_id'; + static const _duplicateCooldown = Duration(seconds: 2); bool _isBusy = false; List _collections = []; Collection? _selectedCollection; bool _loadingCollections = true; + String? _lastProcessedHwId; + DateTime? _lastProcessedAt; @override void initState() { @@ -285,6 +288,15 @@ class ScanTabState extends State { } Future _processHwId(String hwId) async { + final now = DateTime.now(); + if (_lastProcessedHwId == hwId && + _lastProcessedAt != null && + now.difference(_lastProcessedAt!) < _duplicateCooldown) { + return true; + } + _lastProcessedHwId = hwId; + _lastProcessedAt = now; + final collection = _selectedCollection; if (collection == null) return false;