mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-23 05:57:07 +00:00
40 lines
1002 B
Swift
40 lines
1002 B
Swift
import Foundation
|
|
import Combine
|
|
|
|
public class SecretStoreList: ObservableObject {
|
|
|
|
@Published public var stores: [AnySecretStore] = []
|
|
@Published public var modifiableStore: AnySecretStoreModifiable?
|
|
private var sinks: [AnyCancellable] = []
|
|
|
|
public init() {
|
|
}
|
|
|
|
public func add<SecretStoreType: SecretStore>(store: SecretStoreType) {
|
|
addInternal(store: AnySecretStore(store))
|
|
}
|
|
|
|
public func add<SecretStoreType: SecretStoreModifiable>(store: SecretStoreType) {
|
|
let modifiable = AnySecretStoreModifiable(modifiable: store)
|
|
modifiableStore = modifiable
|
|
addInternal(store: modifiable)
|
|
}
|
|
|
|
public var anyAvailable: Bool {
|
|
stores.reduce(false, { $0 || $1.isAvailable })
|
|
}
|
|
|
|
}
|
|
|
|
extension SecretStoreList {
|
|
|
|
private func addInternal(store: AnySecretStore) {
|
|
stores.append(store)
|
|
let sink = store.objectWillChange.sink {
|
|
self.objectWillChange.send()
|
|
}
|
|
sinks.append(sink)
|
|
}
|
|
|
|
}
|