Decouple VPNManager from TunnelKit (#248)

* Drop VPNManager dependency on TunnelKit

* Hook .masksPrivateData to preferences updates
This commit is contained in:
Davide De Rosa 2022-11-10 07:42:08 +01:00 committed by GitHub
parent 7ed27558fc
commit 1b704d7d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 8 deletions

View File

@ -119,5 +119,10 @@ class CoreContext {
profileManager.observeUpdates() profileManager.observeUpdates()
vpnManager.observeUpdates() vpnManager.observeUpdates()
CoreConfiguration.masksPrivateData = vpnManager.masksPrivateData
vpnManager.didUpdatePreferences.sink {
CoreConfiguration.masksPrivateData = $0.masksPrivateData
}.store(in: &cancellables)
} }
} }

View File

@ -28,7 +28,7 @@ import PassepartoutCore
import PassepartoutUtils import PassepartoutUtils
extension VPNManager { extension VPNManager {
private var vpnPreferences: VPNPreferences { var vpnPreferences: VPNPreferences {
DefaultVPNPreferences( DefaultVPNPreferences(
tunnelLogPath: tunnelLogPath, tunnelLogPath: tunnelLogPath,
tunnelLogFormat: tunnelLogFormat, tunnelLogFormat: tunnelLogFormat,

View File

@ -25,8 +25,6 @@
import Foundation import Foundation
import Combine import Combine
import TunnelKitCore
import TunnelKitManager
import PassepartoutCore import PassepartoutCore
import PassepartoutProfiles import PassepartoutProfiles
import PassepartoutProviders import PassepartoutProviders
@ -55,6 +53,8 @@ public final class VPNManager: ObservableObject {
public let currentState: ObservableVPNState public let currentState: ObservableVPNState
public let didUpdatePreferences = PassthroughSubject<VPNPreferences, Never>()
public private(set) var lastError: Error? { public private(set) var lastError: Error? {
get { get {
currentState.lastError currentState.lastError
@ -88,8 +88,6 @@ public final class VPNManager: ObservableObject {
isOnDemandRulesSupported = { true } isOnDemandRulesSupported = { true }
currentState = ObservableVPNState() currentState = ObservableVPNState()
CoreConfiguration.masksPrivateData = masksPrivateData
} }
func reinstate(_ configuration: VPNConfiguration) async { func reinstate(_ configuration: VPNConfiguration) async {
@ -261,6 +259,7 @@ extension VPNManager {
} }
set { set {
store.setValue(newValue, forLocation: StoreKey.tunnelLogPath) store.setValue(newValue, forLocation: StoreKey.tunnelLogPath)
didUpdatePreferences.send(vpnPreferences)
} }
} }
@ -270,6 +269,7 @@ extension VPNManager {
} }
set { set {
store.setValue(newValue, forLocation: StoreKey.tunnelLogFormat) store.setValue(newValue, forLocation: StoreKey.tunnelLogFormat)
didUpdatePreferences.send(vpnPreferences)
} }
} }
@ -279,8 +279,7 @@ extension VPNManager {
} }
set { set {
store.setValue(newValue, forLocation: StoreKey.masksPrivateData) store.setValue(newValue, forLocation: StoreKey.masksPrivateData)
didUpdatePreferences.send(vpnPreferences)
CoreConfiguration.masksPrivateData = masksPrivateData
} }
} }
} }

View File

@ -25,7 +25,7 @@
import Foundation import Foundation
protocol VPNPreferences { public protocol VPNPreferences {
var tunnelLogPath: String? { get } var tunnelLogPath: String? { get }
var tunnelLogFormat: String? { get } var tunnelLogFormat: String? { get }