Add 'didUpdate' subjects in managers
objectWillChange may not work outside SwiftUI. - ProfileManager.didUpdateProfiles - ProviderManager.didUpdateProviders
This commit is contained in:
parent
7771b50b56
commit
7d5f3e63c8
|
@ -32,6 +32,8 @@ public protocol ProfileManager {
|
|||
var activeProfileId: UUID? { get }
|
||||
|
||||
var currentProfileId: UUID? { get set }
|
||||
|
||||
var didUpdateProfiles: PassthroughSubject<Void, Never> { get }
|
||||
|
||||
var didUpdateActiveProfile: PassthroughSubject<UUID?, Never> { get }
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ import Foundation
|
|||
import Combine
|
||||
|
||||
public protocol ProviderManager {
|
||||
var didUpdateProviders: PassthroughSubject<Void, Never> { get }
|
||||
|
||||
func allProviders() -> [ProviderMetadata]
|
||||
|
||||
func provider(withName name: ProviderName) -> ProviderMetadata?
|
||||
|
|
|
@ -79,6 +79,8 @@ public class DefaultProfileManager: ProfileManagerWithCurrentProfile, Observable
|
|||
|
||||
public let currentProfile: ObservableProfile
|
||||
|
||||
public let didUpdateProfiles = PassthroughSubject<Void, Never>()
|
||||
|
||||
public let didUpdateActiveProfile = PassthroughSubject<UUID?, Never>()
|
||||
|
||||
public let didCreateProfile = PassthroughSubject<Profile, Never>()
|
||||
|
@ -329,6 +331,8 @@ extension DefaultProfileManager {
|
|||
pp_log.info("\tActive profile was deleted")
|
||||
self.activeProfileId = nil
|
||||
}
|
||||
|
||||
didUpdateProfiles.send()
|
||||
|
||||
// IMPORTANT: defer task to avoid recursive saves
|
||||
// FIXME: Core Data, not sure about this workaround
|
||||
|
|
|
@ -44,6 +44,8 @@ public class DefaultProviderManager: ProviderManager, ObservableObject, RateLimi
|
|||
|
||||
private let serverRepository: ServerRepository
|
||||
|
||||
public let didUpdateProviders = PassthroughSubject<Void, Never>()
|
||||
|
||||
public init(appBuild: Int, bundleServices: WebServices, webServices: WebServices, persistence: Persistence) {
|
||||
self.appBuild = appBuild
|
||||
self.bundleServices = bundleServices
|
||||
|
@ -118,6 +120,8 @@ public class DefaultProviderManager: ProviderManager, ObservableObject, RateLimi
|
|||
.tryMap { index in
|
||||
self.saveLastAction(self.indexActionName)
|
||||
try self.providerRepository.mergeIndex(index)
|
||||
|
||||
self.didUpdateProviders.send()
|
||||
}.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
|
@ -167,6 +171,8 @@ public class DefaultProviderManager: ProviderManager, ObservableObject, RateLimi
|
|||
vpnProtocol: vpnProtocol,
|
||||
lastUpdate: pub.lastModified ?? Date()
|
||||
)
|
||||
|
||||
self.didUpdateProviders.send()
|
||||
} catch {
|
||||
pp_log.error("Unable to persist \(providerName) infrastructure (\(vpnProtocol)): \(error)")
|
||||
}
|
||||
|
@ -178,6 +184,8 @@ public class DefaultProviderManager: ProviderManager, ObservableObject, RateLimi
|
|||
|
||||
public func reset() {
|
||||
persistence.truncate()
|
||||
|
||||
didUpdateProviders.send()
|
||||
}
|
||||
|
||||
// MARK: RateLimited
|
||||
|
|
Loading…
Reference in New Issue