Merge branch 'refactor-profile-encapsulation'
This commit is contained in:
commit
0f44e9dc71
|
@ -430,7 +430,7 @@ class StatusMenu: NSObject {
|
|||
return
|
||||
}
|
||||
assert(!group.pools.isEmpty)
|
||||
service.setPoolId(group.pools.randomElement()!.id, forProviderProfile: profile)
|
||||
profile.poolId = group.pools.randomElement()!.id
|
||||
vpn.reconnect(completionHandler: nil)
|
||||
|
||||
// update menu
|
||||
|
@ -447,7 +447,7 @@ class StatusMenu: NSObject {
|
|||
guard let profile = service.activeProfile as? ProviderConnectionProfile else {
|
||||
return
|
||||
}
|
||||
service.setPoolId(pool.id, forProviderProfile: profile)
|
||||
profile.poolId = pool.id
|
||||
vpn.reconnect(completionHandler: nil)
|
||||
|
||||
// update menu
|
||||
|
|
|
@ -338,7 +338,7 @@ extension ServiceViewController: ProviderServiceViewDelegate {
|
|||
uncheckedProviderProfile.presetId = fallback
|
||||
}
|
||||
|
||||
service.setPoolId(pool.id, forProviderProfile: uncheckedProviderProfile)
|
||||
uncheckedProviderProfile.poolId = pool.id
|
||||
// vpn.reinstallIfEnabled()
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ public protocol ConnectionProfile: class, EndpointDataSource, CustomStringConver
|
|||
|
||||
var manualNetworkSettings: ProfileNetworkSettings? { get set }
|
||||
|
||||
var serviceDelegate: ConnectionServiceDelegate? { get set }
|
||||
|
||||
func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,28 @@ import Foundation
|
|||
import TunnelKit
|
||||
|
||||
public class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||
|
||||
// XXX: drop after @transient serviceDelegate
|
||||
public enum CodingKeys: CodingKey {
|
||||
case hostname
|
||||
|
||||
case parameters
|
||||
|
||||
case customAddress
|
||||
|
||||
case customProtocol
|
||||
|
||||
case id
|
||||
|
||||
case username
|
||||
|
||||
case trustedNetworks
|
||||
|
||||
case networkChoices
|
||||
|
||||
case manualNetworkSettings
|
||||
}
|
||||
|
||||
public let hostname: String
|
||||
|
||||
public var parameters: OpenVPNTunnelProvider.Configuration
|
||||
|
@ -64,6 +86,8 @@ public class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
|
||||
public var manualNetworkSettings: ProfileNetworkSettings?
|
||||
|
||||
public weak var serviceDelegate: ConnectionServiceDelegate?
|
||||
|
||||
public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration {
|
||||
guard let endpointProtocols = parameters.sessionConfiguration.endpointProtocols, !endpointProtocols.isEmpty else {
|
||||
preconditionFailure("No endpointProtocols")
|
||||
|
|
|
@ -48,6 +48,8 @@ public class PlaceholderConnectionProfile: ConnectionProfile {
|
|||
|
||||
public var manualNetworkSettings: ProfileNetworkSettings?
|
||||
|
||||
public weak var serviceDelegate: ConnectionServiceDelegate?
|
||||
|
||||
public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration {
|
||||
fatalError("Generating configuration from a PlaceholderConnectionProfile")
|
||||
}
|
||||
|
|
|
@ -27,6 +27,30 @@ import Foundation
|
|||
import TunnelKit
|
||||
|
||||
public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||
|
||||
// XXX: drop after @transient serviceDelegate
|
||||
public enum CodingKeys: CodingKey {
|
||||
case name
|
||||
|
||||
case poolId
|
||||
|
||||
case presetId
|
||||
|
||||
case customAddress
|
||||
|
||||
case customProtocol
|
||||
|
||||
case favoriteGroupIds
|
||||
|
||||
case username
|
||||
|
||||
case trustedNetworks
|
||||
|
||||
case networkChoices
|
||||
|
||||
case manualNetworkSettings
|
||||
}
|
||||
|
||||
public let name: Infrastructure.Name
|
||||
|
||||
public var infrastructure: Infrastructure {
|
||||
|
@ -39,6 +63,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
public var poolId: String {
|
||||
didSet {
|
||||
validateEndpoint()
|
||||
serviceDelegate?.connectionService(didUpdate: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +74,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
public var presetId: String {
|
||||
didSet {
|
||||
validateEndpoint()
|
||||
serviceDelegate?.connectionService(didUpdate: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +148,8 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
|
||||
public var manualNetworkSettings: ProfileNetworkSettings?
|
||||
|
||||
public weak var serviceDelegate: ConnectionServiceDelegate?
|
||||
|
||||
public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration {
|
||||
guard let pool = pool else {
|
||||
preconditionFailure("Nil pool?")
|
||||
|
@ -214,10 +242,3 @@ public extension ProviderConnectionProfile {
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public extension ConnectionService {
|
||||
func setPoolId(_ poolId: String, forProviderProfile profile: ProviderConnectionProfile) {
|
||||
profile.poolId = poolId
|
||||
delegate?.connectionService(didUpdate: profile)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue