Better observe updates explicitly after init

This commit is contained in:
Davide De Rosa 2022-04-18 15:32:28 +02:00
parent 5cafd9794d
commit f5c87d43c2
3 changed files with 9 additions and 4 deletions

View File

@ -139,6 +139,9 @@ class AppContext {
self.isEligibleForOnDemandRules() self.isEligibleForOnDemandRules()
} }
profileManager.observeUpdates()
vpnManager.observeUpdates()
// app // app
reviewer.eventCountBeforeRating = Constants.Rating.eventCount reviewer.eventCountBeforeRating = Constants.Rating.eventCount

View File

@ -78,8 +78,6 @@ public class VPNManager: ObservableObject, RateLimited {
isOnDemandRulesSupported = { true } isOnDemandRulesSupported = { true }
currentState = ObservableState() currentState = ObservableState()
observeStrategy()
observeProfileManager()
} }
public func toggle() -> Bool { public func toggle() -> Bool {
@ -156,6 +154,11 @@ public class VPNManager: ObservableObject, RateLimited {
// MARK: Observation // MARK: Observation
extension VPNManager { extension VPNManager {
public func observeUpdates() {
observeStrategy()
observeProfileManager()
}
private func observeStrategy() { private func observeStrategy() {
strategy.observe(into: currentState) strategy.observe(into: currentState)
} }

View File

@ -85,7 +85,6 @@ public class ProfileManager: ObservableObject {
self.strategy = strategy self.strategy = strategy
currentProfile = ObservableProfile() currentProfile = ObservableProfile()
observeUpdates()
} }
} }
@ -275,7 +274,7 @@ extension ProfileManager {
} }
extension ProfileManager { extension ProfileManager {
private func observeUpdates() { public func observeUpdates() {
strategy.willUpdateProfiles() strategy.willUpdateProfiles()
.dropFirst() .dropFirst()
.sink { .sink {