Do not necessarily reconnect on intent

Trust intents just reinstall VPN profile.
This commit is contained in:
Davide De Rosa 2019-03-10 13:55:22 +01:00
parent 670139d807
commit b841552121
1 changed files with 13 additions and 15 deletions

View File

@ -145,15 +145,9 @@ class InteractionsHandler {
return return
} }
service.activateProfile(profile) service.activateProfile(profile)
reconnectVPN(service: service) refreshVPN(service: service, doReconnect: true)
} }
private static func handleDisableVPN(_ intent: DisableVPNIntent, interaction: INInteraction) {
VPN.shared.disconnect { (error) in
notifyServiceController()
}
}
private static func handleMoveToLocation(_ intent: MoveToLocationIntent, interaction: INInteraction) { private static func handleMoveToLocation(_ intent: MoveToLocationIntent, interaction: INInteraction) {
guard let providerId = intent.providerId, let poolId = intent.poolId else { guard let providerId = intent.providerId, let poolId = intent.poolId else {
return return
@ -172,9 +166,15 @@ class InteractionsHandler {
providerProfile.poolId = poolId providerProfile.poolId = poolId
service.activateProfile(providerProfile) service.activateProfile(providerProfile)
reconnectVPN(service: service) refreshVPN(service: service, doReconnect: true)
} }
private static func handleDisableVPN(_ intent: DisableVPNIntent, interaction: INInteraction) {
VPN.shared.disconnect { (error) in
notifyServiceController()
}
}
private static func handleCurrentNetwork(trust: Bool, interaction: INInteraction) { private static func handleCurrentNetwork(trust: Bool, interaction: INInteraction) {
guard let currentWifi = Utils.currentWifiNetworkName() else { guard let currentWifi = Utils.currentWifiNetworkName() else {
return return
@ -183,7 +183,7 @@ class InteractionsHandler {
service.preferences.trustedWifis[currentWifi] = trust service.preferences.trustedWifis[currentWifi] = trust
TransientStore.shared.serialize(withProfiles: false) TransientStore.shared.serialize(withProfiles: false)
reconnectVPN(service: service) refreshVPN(service: service, doReconnect: false)
} }
private static func handleCellularNetwork(trust: Bool, interaction: INInteraction) { private static func handleCellularNetwork(trust: Bool, interaction: INInteraction) {
@ -194,10 +194,10 @@ class InteractionsHandler {
service.preferences.trustsMobileNetwork = trust service.preferences.trustsMobileNetwork = trust
TransientStore.shared.serialize(withProfiles: false) TransientStore.shared.serialize(withProfiles: false)
reconnectVPN(service: service) refreshVPN(service: service, doReconnect: false)
} }
private static func reconnectVPN(service: ConnectionService) { private static func refreshVPN(service: ConnectionService, doReconnect: Bool) {
let configuration: VPNConfiguration let configuration: VPNConfiguration
do { do {
configuration = try service.vpnConfiguration() configuration = try service.vpnConfiguration()
@ -208,13 +208,11 @@ class InteractionsHandler {
} }
let vpn = VPN.shared let vpn = VPN.shared
switch vpn.status { if doReconnect {
case .connected:
vpn.reconnect(configuration: configuration) { (error) in vpn.reconnect(configuration: configuration) { (error) in
notifyServiceController() notifyServiceController()
} }
} else {
default:
vpn.install(configuration: configuration) { (error) in vpn.install(configuration: configuration) { (error) in
notifyServiceController() notifyServiceController()
} }