diff --git a/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift b/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift index cf72c503..f3f48d3d 100644 --- a/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift +++ b/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift @@ -45,14 +45,12 @@ public final class ExtendedTunnel: ObservableObject { environment.environmentValue(forKey: key) } - @Published public private(set) var lastErrorCode: PassepartoutError.Code? { didSet { pp_log(.app, .info, "ExtendedTunnel.lastErrorCode -> \(lastErrorCode?.rawValue ?? "nil")") } } - @Published public private(set) var dataCount: DataCount? private var subscriptions: Set @@ -92,6 +90,10 @@ extension ExtendedTunnel { tunnel.currentProfile ?? lastUsedProfile } + public var currentProfiles: [Profile.ID: TunnelCurrentProfile] { + tunnel.currentProfiles + } + public var currentProfilePublisher: AnyPublisher { tunnel .$currentProfile @@ -151,33 +153,31 @@ extension ExtendedTunnel { private extension ExtendedTunnel { func observeObjects() { tunnel - .$status + .$currentProfile .receive(on: DispatchQueue.main) .sink { [weak self] in guard let self else { return } - switch $0 { + + // update last used profile + if let id = $0?.id { + defaults?.set(id.uuidString, forKey: AppPreference.lastUsedProfileId.key) + } + + // follow status updates + switch $0?.status ?? .inactive { + case .active: + break case .activating: lastErrorCode = nil - + dataCount = nil default: lastErrorCode = value(forKey: TunnelEnvironmentKeys.lastErrorCode) - } - if $0 != .active { dataCount = nil } - } - .store(in: &subscriptions) - tunnel - .$currentProfile - .receive(on: DispatchQueue.main) - .sink { [weak self] in - if let id = $0?.id { - self?.defaults?.set(id.uuidString, forKey: AppPreference.lastUsedProfileId.key) - } - self?.objectWillChange.send() + objectWillChange.send() } .store(in: &subscriptions) @@ -195,6 +195,7 @@ private extension ExtendedTunnel { if tunnel.status == .active { dataCount = value(forKey: TunnelEnvironmentKeys.dataCount) } + objectWillChange.send() } .store(in: &subscriptions) } @@ -226,7 +227,11 @@ private extension ExtendedTunnel { let uuid = UUID(uuidString: uuidString) else { return nil } - return TunnelCurrentProfile(id: uuid, onDemand: false) + return TunnelCurrentProfile( + id: uuid, + status: .inactive, + onDemand: false + ) } } diff --git a/Packages/App/Tests/CommonLibraryTests/Business/ExtendedTunnelTests.swift b/Packages/App/Tests/CommonLibraryTests/Business/ExtendedTunnelTests.swift index c9591dd8..36ebb8b1 100644 --- a/Packages/App/Tests/CommonLibraryTests/Business/ExtendedTunnelTests.swift +++ b/Packages/App/Tests/CommonLibraryTests/Business/ExtendedTunnelTests.swift @@ -48,9 +48,9 @@ extension ExtendedTunnelTests { let exp = expectation(description: "Last error code") var didCall = false sut - .$lastErrorCode + .objectWillChange .sink { - if !didCall, $0 != nil { + if !didCall, sut.lastErrorCode != nil { didCall = true exp.fulfill() } @@ -78,9 +78,9 @@ extension ExtendedTunnelTests { let exp = expectation(description: "Data count") var didCall = false sut - .$dataCount + .objectWillChange .sink { - if !didCall, $0 != nil { + if !didCall, sut.dataCount != nil { didCall = true exp.fulfill() } diff --git a/Packages/PassepartoutKit-Source b/Packages/PassepartoutKit-Source index e501530c..65582f66 160000 --- a/Packages/PassepartoutKit-Source +++ b/Packages/PassepartoutKit-Source @@ -1 +1 @@ -Subproject commit e501530c9d396bf800fc64c0f1e29dfba9493786 +Subproject commit 65582f668f4dccda310820c209865e8818179f24