mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-13 11:22:06 +00:00
Follow tunnel status from current profile (#1146)
In preparation for #218, when there will be "multiple current profiles", i.e. the enabled profiles in the OS settings.
This commit is contained in:
parent
bb21f5be05
commit
eb32aed2a4
@ -45,14 +45,12 @@ public final class ExtendedTunnel: ObservableObject {
|
|||||||
environment.environmentValue(forKey: key)
|
environment.environmentValue(forKey: key)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Published
|
|
||||||
public private(set) var lastErrorCode: PassepartoutError.Code? {
|
public private(set) var lastErrorCode: PassepartoutError.Code? {
|
||||||
didSet {
|
didSet {
|
||||||
pp_log(.app, .info, "ExtendedTunnel.lastErrorCode -> \(lastErrorCode?.rawValue ?? "nil")")
|
pp_log(.app, .info, "ExtendedTunnel.lastErrorCode -> \(lastErrorCode?.rawValue ?? "nil")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Published
|
|
||||||
public private(set) var dataCount: DataCount?
|
public private(set) var dataCount: DataCount?
|
||||||
|
|
||||||
private var subscriptions: Set<AnyCancellable>
|
private var subscriptions: Set<AnyCancellable>
|
||||||
@ -92,6 +90,10 @@ extension ExtendedTunnel {
|
|||||||
tunnel.currentProfile ?? lastUsedProfile
|
tunnel.currentProfile ?? lastUsedProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var currentProfiles: [Profile.ID: TunnelCurrentProfile] {
|
||||||
|
tunnel.currentProfiles
|
||||||
|
}
|
||||||
|
|
||||||
public var currentProfilePublisher: AnyPublisher<TunnelCurrentProfile?, Never> {
|
public var currentProfilePublisher: AnyPublisher<TunnelCurrentProfile?, Never> {
|
||||||
tunnel
|
tunnel
|
||||||
.$currentProfile
|
.$currentProfile
|
||||||
@ -151,33 +153,31 @@ extension ExtendedTunnel {
|
|||||||
private extension ExtendedTunnel {
|
private extension ExtendedTunnel {
|
||||||
func observeObjects() {
|
func observeObjects() {
|
||||||
tunnel
|
tunnel
|
||||||
.$status
|
.$currentProfile
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] in
|
.sink { [weak self] in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
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:
|
case .activating:
|
||||||
lastErrorCode = nil
|
lastErrorCode = nil
|
||||||
|
dataCount = nil
|
||||||
default:
|
default:
|
||||||
lastErrorCode = value(forKey: TunnelEnvironmentKeys.lastErrorCode)
|
lastErrorCode = value(forKey: TunnelEnvironmentKeys.lastErrorCode)
|
||||||
}
|
|
||||||
if $0 != .active {
|
|
||||||
dataCount = nil
|
dataCount = nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.store(in: &subscriptions)
|
|
||||||
|
|
||||||
tunnel
|
objectWillChange.send()
|
||||||
.$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()
|
|
||||||
}
|
}
|
||||||
.store(in: &subscriptions)
|
.store(in: &subscriptions)
|
||||||
|
|
||||||
@ -195,6 +195,7 @@ private extension ExtendedTunnel {
|
|||||||
if tunnel.status == .active {
|
if tunnel.status == .active {
|
||||||
dataCount = value(forKey: TunnelEnvironmentKeys.dataCount)
|
dataCount = value(forKey: TunnelEnvironmentKeys.dataCount)
|
||||||
}
|
}
|
||||||
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
.store(in: &subscriptions)
|
.store(in: &subscriptions)
|
||||||
}
|
}
|
||||||
@ -226,7 +227,11 @@ private extension ExtendedTunnel {
|
|||||||
let uuid = UUID(uuidString: uuidString) else {
|
let uuid = UUID(uuidString: uuidString) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return TunnelCurrentProfile(id: uuid, onDemand: false)
|
return TunnelCurrentProfile(
|
||||||
|
id: uuid,
|
||||||
|
status: .inactive,
|
||||||
|
onDemand: false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ extension ExtendedTunnelTests {
|
|||||||
let exp = expectation(description: "Last error code")
|
let exp = expectation(description: "Last error code")
|
||||||
var didCall = false
|
var didCall = false
|
||||||
sut
|
sut
|
||||||
.$lastErrorCode
|
.objectWillChange
|
||||||
.sink {
|
.sink {
|
||||||
if !didCall, $0 != nil {
|
if !didCall, sut.lastErrorCode != nil {
|
||||||
didCall = true
|
didCall = true
|
||||||
exp.fulfill()
|
exp.fulfill()
|
||||||
}
|
}
|
||||||
@ -78,9 +78,9 @@ extension ExtendedTunnelTests {
|
|||||||
let exp = expectation(description: "Data count")
|
let exp = expectation(description: "Data count")
|
||||||
var didCall = false
|
var didCall = false
|
||||||
sut
|
sut
|
||||||
.$dataCount
|
.objectWillChange
|
||||||
.sink {
|
.sink {
|
||||||
if !didCall, $0 != nil {
|
if !didCall, sut.dataCount != nil {
|
||||||
didCall = true
|
didCall = true
|
||||||
exp.fulfill()
|
exp.fulfill()
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit e501530c9d396bf800fc64c0f1e29dfba9493786
|
Subproject commit 65582f668f4dccda310820c209865e8818179f24
|
Loading…
Reference in New Issue
Block a user