mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-08-27 07:30:57 +00:00
Fix concurrency issue on key insertion.
This commit is contained in:
parent
d42b4ed699
commit
8c2f9c14cd
@ -1,7 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Observation
|
import Observation
|
||||||
import Security
|
import Security
|
||||||
import CryptoTokenKit
|
@preconcurrency import CryptoTokenKit
|
||||||
import LocalAuthentication
|
import LocalAuthentication
|
||||||
import SecretKit
|
import SecretKit
|
||||||
|
|
||||||
@ -37,17 +37,18 @@ extension SmartCard {
|
|||||||
|
|
||||||
/// Initializes a Store.
|
/// Initializes a Store.
|
||||||
public init() {
|
public init() {
|
||||||
Task { @MainActor in
|
Task {
|
||||||
|
await MainActor.run {
|
||||||
if let tokenID = smartcardTokenID {
|
if let tokenID = smartcardTokenID {
|
||||||
state.isAvailable = true
|
state.isAvailable = true
|
||||||
state.watcher.addRemovalHandler(self.smartcardRemoved, forTokenID: tokenID)
|
state.watcher.addRemovalHandler(self.smartcardRemoved, forTokenID: tokenID)
|
||||||
}
|
}
|
||||||
loadSecrets()
|
loadSecrets()
|
||||||
state.watcher.setInsertionHandler { id in
|
}
|
||||||
// Setting insertion handler will cause it to be called immediately.
|
// Doing this inside a regular mainactor handler casues thread assertions in CryptoTokenKit to blow up when the handler executes.
|
||||||
// Make a thread jump so we don't hit a recursive lock attempt.
|
await state.watcher.setInsertionHandler { id in
|
||||||
Task {
|
Task {
|
||||||
self.smartcardInserted(for: id)
|
await self.smartcardInserted(for: id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user