From 8ad2d60082687cfa0b63dd9b3c282e3ccc58906e Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 26 Aug 2025 23:15:17 -0700 Subject: [PATCH] Remove logic to deal with sending/not sending distrib notifications (#641) --- .../SecureEnclaveStore.swift | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift index b94dc5e..737ac5d 100644 --- a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift +++ b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift @@ -23,7 +23,11 @@ extension SecureEnclave { @MainActor public init() { loadSecrets() Task { - for await _ in DistributedNotificationCenter.default().notifications(named: .secretStoreUpdated) { + for await note in DistributedNotificationCenter.default().notifications(named: .secretStoreUpdated) { + guard Constants.notificationToken != (note.object as? String) else { + // Don't reload if we're the ones triggering this by reloading. + return + } reloadSecrets() } } @@ -93,7 +97,13 @@ extension SecureEnclave { } @MainActor public func reloadSecrets() { - reloadSecretsInternal(notifyAgent: false) + let before = secrets + secrets.removeAll() + loadSecrets() + if secrets != before { + NotificationCenter.default.post(name: .secretStoreReloaded, object: self) + DistributedNotificationCenter.default().postNotificationName(.secretStoreUpdated, object: Constants.notificationToken, deliverImmediately: true) + } } // MARK: SecretStoreModifiable @@ -194,18 +204,6 @@ extension SecureEnclave { extension SecureEnclave.Store { - @MainActor private func reloadSecretsInternal(notifyAgent: Bool = true) { - let before = secrets - secrets.removeAll() - loadSecrets() - if secrets != before { - NotificationCenter.default.post(name: .secretStoreReloaded, object: self) - if notifyAgent { - DistributedNotificationCenter.default().postNotificationName(.secretStoreUpdated, object: nil, deliverImmediately: true) - } - } - } - /// Loads all secrets from the store. @MainActor private func loadSecrets() { let queryAttributes = KeychainDictionary([ @@ -286,6 +284,7 @@ extension SecureEnclave.Store { enum Constants { static let keyClass = kSecClassGenericPassword as String static let keyTag = Data("com.maxgoedjen.secretive.secureenclave.key".utf8) + static let notificationToken = UUID().uuidString } struct UnsupportedAlgorithmError: Error {}