Add 'didUpdate' subjects in managers

objectWillChange may not work outside SwiftUI.

- ProfileManager.didUpdateProfiles

- ProviderManager.didUpdateProviders
This commit is contained in:
Davide De Rosa 2022-07-15 08:41:05 +02:00
parent 7771b50b56
commit 7d5f3e63c8
4 changed files with 16 additions and 0 deletions

View File

@ -33,6 +33,8 @@ public protocol ProfileManager {
var currentProfileId: UUID? { get set }
var didUpdateProfiles: PassthroughSubject<Void, Never> { get }
var didUpdateActiveProfile: PassthroughSubject<UUID?, Never> { get }
var didCreateProfile: PassthroughSubject<Profile, Never> { get }

View File

@ -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?

View File

@ -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>()
@ -330,6 +332,8 @@ extension DefaultProfileManager {
self.activeProfileId = nil
}
didUpdateProfiles.send()
// IMPORTANT: defer task to avoid recursive saves
// FIXME: Core Data, not sure about this workaround
Task {

View File

@ -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