Skip to content

Commit 51aafeb

Browse files
committed
Fixes problems around holding on to the YubiKey when in background
1 parent 5397b5d commit 51aafeb

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Authenticator/Model/MainViewModel.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ class MainViewModel: ObservableObject {
125125
}
126126
}
127127
}
128-
128+
129+
@MainActor func closeConnections() {
130+
OATHSessionHandler.shared.smartCardConnection?.stop()
131+
OATHSessionHandler.shared.accessoryConnection?.stop()
132+
}
133+
129134
@MainActor func stop() {
130135
sessionTask?.cancel()
131136
sessionTask = nil

Authenticator/Model/OATHSession.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class OATHSessionHandler: NSObject, YKFManagerDelegate {
4848

4949
typealias ClosingCallback = ((_ error: Error?) -> Void)
5050

51-
private var nfcConnection: YKFNFCConnection?
52-
private var smartCardConnection: YKFSmartCardConnection?
53-
private var accessoryConnection: YKFAccessoryConnection?
51+
var nfcConnection: YKFNFCConnection?
52+
var smartCardConnection: YKFSmartCardConnection?
53+
var accessoryConnection: YKFAccessoryConnection?
5454

5555
private var currentSession: YKFOATHSession?
5656

Authenticator/UI/MainView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ struct MainView: View {
227227
}
228228
}
229229
.onChange(of: scenePhase) { phase in
230-
if phase == .active && didEnterBackground {
231-
didEnterBackground = false
230+
if phase == .active {
232231
model.start() // This is called when app becomes active
233-
} else if phase == .background {
234-
didEnterBackground = true
232+
} else if phase == .background || phase == .inactive {
233+
let _ = UIApplication.shared.beginBackgroundTask { }
235234
model.stop()
235+
model.closeConnections()
236236
}
237237
}
238238
.onChange(of: model.showTouchToast) { showToast in

0 commit comments

Comments
 (0)