Skip to content

Commit ee2861e

Browse files
committed
Limit scanning (not haptic feedback) to one result per second
1 parent fa48007 commit ee2861e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Authenticator/Source/AppController.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class AppController {
5353
dispatchAction: self.handleAction
5454
)
5555
}()
56-
private var lastHapticFeedback = Date(timeIntervalSince1970: 0)
5756

5857
init() {
5958
do {
@@ -202,12 +201,8 @@ class AppController {
202201
// Provide haptic feedback to accompany success and error messages
203202
private func generateFeedback(for notificationFeedbackType: UINotificationFeedbackType) {
204203
if #available(iOS 10.0, *) {
205-
let now = Date()
206-
if now.timeIntervalSince(lastHapticFeedback) > 1 {
207-
lastHapticFeedback = now
208-
let feedbackGenerator = UINotificationFeedbackGenerator()
209-
feedbackGenerator.notificationOccurred(notificationFeedbackType)
210-
}
204+
let feedbackGenerator = UINotificationFeedbackGenerator()
205+
feedbackGenerator.notificationOccurred(notificationFeedbackType)
211206
}
212207
}
213208

Authenticator/Source/TokenScannerViewController.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,18 @@ final class TokenScannerViewController: UIViewController, QRScannerDelegate {
184184

185185
// MARK: QRScannerDelegate
186186

187+
private var lastScanTime = Date(timeIntervalSince1970: 0)
188+
private let minimumScanInterval: TimeInterval = 1
189+
187190
func handleDecodedText(_ text: String) {
188191
guard viewModel.isScanning else {
189192
return
190193
}
191-
dispatchAction(.scannerDecodedText(text))
194+
195+
let now = Date()
196+
if now.timeIntervalSince(lastScanTime) > minimumScanInterval {
197+
lastScanTime = now
198+
dispatchAction(.scannerDecodedText(text))
199+
}
192200
}
193201
}

0 commit comments

Comments
 (0)