Merge branch 'refactor-intents'

This commit is contained in:
Davide De Rosa 2019-03-18 17:19:23 +01:00
commit 66e14b4e60
6 changed files with 94 additions and 69 deletions

View File

@ -161,7 +161,7 @@ extension AppDelegate {
return false
}
if #available(iOS 12, *) {
InteractionsHandler.handleInteraction(interaction)
IntentDispatcher.handleInteraction(interaction, completionHandler: nil)
}
return true
}

View File

@ -225,7 +225,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
service.removeProfile(rowProfile)
if #available(iOS 12, *) {
InteractionsHandler.forgetProfile(withKey: rowProfile)
IntentDispatcher.forgetProfile(withKey: rowProfile)
}
}
@ -473,7 +473,7 @@ extension OrganizerViewController: ConnectionServiceDelegate {
tableView.reloadData()
if #available(iOS 12, *) {
InteractionsHandler.donateConnection(with: profile)
IntentDispatcher.donateConnection(with: profile)
}
// XXX: hack around bad replace when detail presented in compact view
@ -520,7 +520,7 @@ extension OrganizerViewController: ConnectionServiceDelegate {
tableView.reloadData()
if #available(iOS 12, *) {
InteractionsHandler.donateConnection(with: profile)
IntentDispatcher.donateConnection(with: profile)
}
}
}

View File

@ -254,8 +254,8 @@ class ServiceViewController: UIViewController, TableModelHost {
}
if #available(iOS 12, *) {
InteractionsHandler.donateEnableVPN()
InteractionsHandler.donateDisableVPN()
IntentDispatcher.donateEnableVPN()
IntentDispatcher.donateDisableVPN()
}
}
@ -790,8 +790,8 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
case .trustedAddCurrentWiFi:
if #available(iOS 12, *) {
InteractionsHandler.donateTrustCurrentNetwork()
InteractionsHandler.donateUntrustCurrentNetwork()
IntentDispatcher.donateTrustCurrentNetwork()
IntentDispatcher.donateUntrustCurrentNetwork()
}
guard trustedNetworks.addCurrentWifi() else {
@ -839,8 +839,8 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
case .trustedMobile:
if #available(iOS 12, *) {
InteractionsHandler.donateTrustCellularNetwork()
InteractionsHandler.donateUntrustCellularNetwork()
IntentDispatcher.donateTrustCellularNetwork()
IntentDispatcher.donateUntrustCellularNetwork()
}
trustedNetworks.setMobile(cell.isOn)
@ -1104,7 +1104,7 @@ extension ServiceViewController: ProviderPoolViewControllerDelegate {
vpn.reinstallIfEnabled()
if #available(iOS 12, *) {
InteractionsHandler.donateConnection(with: uncheckedProviderProfile)
IntentDispatcher.donateConnection(with: uncheckedProviderProfile)
}
}
}

View File

@ -63,7 +63,6 @@
0E3DA371215CB5BF00B40FC9 /* VersionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3DA370215CB5BF00B40FC9 /* VersionViewController.swift */; };
0E4C9CBB20DCF0D600A0C59C /* DestructiveTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4C9CBA20DCF0D600A0C59C /* DestructiveTableViewCell.swift */; };
0E4FD7F120D58618002221FF /* Macros.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4FD7F020D58618002221FF /* Macros.swift */; };
0E50E7C6223318A500D5F76C /* InteractionsHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E50E7C5223318A500D5F76C /* InteractionsHandler.swift */; };
0E57F63C20C83FC5008323CF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E57F63B20C83FC5008323CF /* AppDelegate.swift */; };
0E57F63E20C83FC5008323CF /* ServiceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E57F63D20C83FC5008323CF /* ServiceViewController.swift */; };
0E57F64120C83FC5008323CF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E57F63F20C83FC5008323CF /* Main.storyboard */; };
@ -86,6 +85,8 @@
0ED38ADA213F44D00004D387 /* Organizer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0ED38ADC213F44D00004D387 /* Organizer.storyboard */; };
0ED38AEA214054A50004D387 /* OptionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED38AE9214054A50004D387 /* OptionViewController.swift */; };
0ED38AEC2141260D0004D387 /* ConfigurationModificationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED38AEB2141260D0004D387 /* ConfigurationModificationDelegate.swift */; };
0ED993B1223FF8C700B0F9C9 /* IntentDispatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED993B0223FF8C700B0F9C9 /* IntentDispatcher.swift */; };
0ED993B2223FF92000B0F9C9 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0EFE0D5C2233D1C7002B5E8C /* Intents.intentdefinition */; };
0EDE8DC420C86910004C739C /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EDE8DC320C86910004C739C /* PacketTunnelProvider.swift */; };
0EDE8DC820C86910004C739C /* Passepartout-Tunnel.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 0EDE8DBF20C86910004C739C /* Passepartout-Tunnel.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
0EE3BBB2215ED3A900F30952 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE3BBB1215ED3A900F30952 /* AboutViewController.swift */; };
@ -95,7 +96,7 @@
0EFBFAC121AC464800887A8C /* CreditsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFBFAC021AC464800887A8C /* CreditsViewController.swift */; };
0EFD943E215BE10800529B64 /* IssueReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFD943D215BE10800529B64 /* IssueReporter.swift */; };
0EFD9440215BED8E00529B64 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFD943F215BED8E00529B64 /* LabelViewController.swift */; };
0EFE0D5A2233D1C7002B5E8C /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0EFE0D5C2233D1C7002B5E8C /* Intents.intentdefinition */; };
0EFE0D5A2233D1C7002B5E8C /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0EFE0D5C2233D1C7002B5E8C /* Intents.intentdefinition */; settings = {ATTRIBUTES = (no_codegen, ); }; };
390EEC911382C4814FB97475 /* Pods_Passepartout_iOS_Tunnel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D0C619B826C7140001C0F32 /* Pods_Passepartout_iOS_Tunnel.framework */; };
4557767FEDE747E8096E8D2B /* Pods_Passepartout_CoreTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F0B03FAF4A0F1620CCA4B19 /* Pods_Passepartout_CoreTests.framework */; };
61E05ED5CCEEA859AD1752F3 /* Pods_Passepartout_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E9FBA5419C4B758FB5D68E96 /* Pods_Passepartout_iOS.framework */; };
@ -182,7 +183,6 @@
0E4FD7ED20D539A0002221FF /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
0E4FD7F020D58618002221FF /* Macros.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Macros.swift; sourceTree = "<group>"; };
0E4FD80420D683A2002221FF /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/NetworkExtension.framework; sourceTree = DEVELOPER_DIR; };
0E50E7C5223318A500D5F76C /* InteractionsHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InteractionsHandler.swift; sourceTree = "<group>"; };
0E57F63820C83FC5008323CF /* Passepartout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Passepartout.app; sourceTree = BUILT_PRODUCTS_DIR; };
0E57F63B20C83FC5008323CF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
0E57F63D20C83FC5008323CF /* ServiceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceViewController.swift; sourceTree = "<group>"; };
@ -232,6 +232,7 @@
0ED38AF1214177920004D387 /* VPNProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNProvider.swift; sourceTree = "<group>"; };
0ED824C920D12B8700F2FE9E /* ToggleTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleTableViewCell.swift; sourceTree = "<group>"; };
0ED824CD20D12DBE00F2FE9E /* SettingTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingTableViewCell.swift; sourceTree = "<group>"; };
0ED993B0223FF8C700B0F9C9 /* IntentDispatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IntentDispatcher.swift; path = Passepartout/Sources/Intents/IntentDispatcher.swift; sourceTree = SOURCE_ROOT; };
0EDE8DBF20C86910004C739C /* Passepartout-Tunnel.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Passepartout-Tunnel.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
0EDE8DC320C86910004C739C /* PacketTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PacketTunnelProvider.swift; sourceTree = "<group>"; };
0EDE8DC520C86910004C739C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -356,8 +357,8 @@
0E50E7C422330E5100D5F76C /* Intents */ = {
isa = PBXGroup;
children = (
0ED993B0223FF8C700B0F9C9 /* IntentDispatcher.swift */,
0EFE0D5C2233D1C7002B5E8C /* Intents.intentdefinition */,
0E50E7C5223318A500D5F76C /* InteractionsHandler.swift */,
);
path = Intents;
sourceTree = "<group>";
@ -394,7 +395,6 @@
0E1066CA20E0F85C004F98B7 /* Cells */,
0ECEE44C20E1120F00A6BB43 /* Tables */,
0EDE8DF120C93ED8004C739C /* Scenes */,
0E50E7C422330E5100D5F76C /* Intents */,
0EDE8DE220C86A13004C739C /* Passepartout.entitlements */,
0E57F63B20C83FC5008323CF /* AppDelegate.swift */,
0E57F63F20C83FC5008323CF /* Main.storyboard */,
@ -524,6 +524,7 @@
0ED31C0E20CF09890027975F /* Model */,
0ED31C1B20CF0ACE0027975F /* Services */,
0E4FD7D920D3E43F002221FF /* VPN */,
0E50E7C422330E5100D5F76C /* Intents */,
0E39BCF2214DA9310035E9DE /* AppConstants.swift */,
0E6BE13920CFB76800A6DD36 /* ApplicationError.swift */,
0EDE8DED20C93E4C004C739C /* GroupConstants.swift */,
@ -959,12 +960,14 @@
0E3152BB223FA03D00F61841 /* AppConstants.swift in Sources */,
0E3152CA223FA04D00F61841 /* InfrastructurePreset.swift in Sources */,
0E3152CE223FA05400F61841 /* ConnectionService.swift in Sources */,
0ED993B1223FF8C700B0F9C9 /* IntentDispatcher.swift in Sources */,
0E3152BE223FA03D00F61841 /* Reviewer.swift in Sources */,
0E3152C3223FA04800F61841 /* StandardVPNProvider.swift in Sources */,
0E3152D1223FA05400F61841 /* Credentials.swift in Sources */,
0E3152CD223FA05400F61841 /* ConnectionProfile.swift in Sources */,
0E3152BC223FA03D00F61841 /* ApplicationError.swift in Sources */,
0E3152C9223FA04D00F61841 /* InfrastructureFactory.swift in Sources */,
0ED993B2223FF92000B0F9C9 /* Intents.intentdefinition in Sources */,
0E3152D3223FA05400F61841 /* EndpointDataSource.swift in Sources */,
0E3152D4223FA05400F61841 /* Preferences.swift in Sources */,
0E3152C0223FA03D00F61841 /* Utils.swift in Sources */,
@ -1002,7 +1005,6 @@
0EFE0D5A2233D1C7002B5E8C /* Intents.intentdefinition in Sources */,
0E3DA371215CB5BF00B40FC9 /* VersionViewController.swift in Sources */,
0E05C5D620D1645F006EE732 /* SwiftGen+Scenes.swift in Sources */,
0E50E7C6223318A500D5F76C /* InteractionsHandler.swift in Sources */,
0EFD9440215BED8E00529B64 /* LabelViewController.swift in Sources */,
0ED31C2C20CF2D6F0027975F /* ProviderPoolViewController.swift in Sources */,
0E2B494020FCFF990094784C /* Theme+Titles.swift in Sources */,

View File

@ -1,6 +1,6 @@
//
// InteractionsHandler.swift
// Passepartout-iOS
// IntentDispatcher.swift
// Passepartout
//
// Created by Davide De Rosa on 3/8/19.
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
@ -26,23 +26,22 @@
import Foundation
import Intents
import SwiftyBeaver
import Passepartout_Core
private let log = SwiftyBeaver.self
extension Notification.Name {
public extension Notification.Name {
static let IntentDidUpdateService = Notification.Name("IntentDidUpdateService")
}
@available(iOS 12, *)
class InteractionsHandler {
public class IntentDispatcher {
private class Groups {
static let vpn = "VPN"
static let trust = "Trust"
}
static func donateConnection(with profile: ConnectionProfile) {
public static func donateConnection(with profile: ConnectionProfile) {
let profileKey = ProfileKey(profile)
let genericIntent: INIntent
@ -64,7 +63,7 @@ class InteractionsHandler {
interaction.donateAndLog()
}
static func donateEnableVPN() {
public static func donateEnableVPN() {
let intent = EnableVPNIntent()
let interaction = INInteraction(intent: intent, response: nil)
@ -72,7 +71,7 @@ class InteractionsHandler {
interaction.donateAndLog()
}
static func donateDisableVPN() {
public static func donateDisableVPN() {
let intent = DisableVPNIntent()
let interaction = INInteraction(intent: intent, response: nil)
@ -80,7 +79,7 @@ class InteractionsHandler {
interaction.donateAndLog()
}
static func donateTrustCurrentNetwork() {
public static func donateTrustCurrentNetwork() {
let intent = TrustCurrentNetworkIntent()
let interaction = INInteraction(intent: intent, response: nil)
@ -88,7 +87,7 @@ class InteractionsHandler {
interaction.donateAndLog()
}
static func donateUntrustCurrentNetwork() {
public static func donateUntrustCurrentNetwork() {
let intent = UntrustCurrentNetworkIntent()
let interaction = INInteraction(intent: intent, response: nil)
@ -96,7 +95,7 @@ class InteractionsHandler {
interaction.donateAndLog()
}
static func donateTrustCellularNetwork() {
public static func donateTrustCellularNetwork() {
let intent = TrustCellularNetworkIntent()
let interaction = INInteraction(intent: intent, response: nil)
@ -104,7 +103,7 @@ class InteractionsHandler {
interaction.donateAndLog()
}
static func donateUntrustCellularNetwork() {
public static func donateUntrustCellularNetwork() {
let intent = UntrustCellularNetworkIntent()
let interaction = INInteraction(intent: intent, response: nil)
@ -113,30 +112,38 @@ class InteractionsHandler {
}
//
static func handleInteraction(_ interaction: INInteraction) {
if let custom = interaction.intent as? ConnectVPNIntent {
handleConnectVPN(custom, interaction: interaction)
} else if let custom = interaction.intent as? EnableVPNIntent {
handleEnableVPN(custom, interaction: interaction)
} else if let custom = interaction.intent as? DisableVPNIntent {
handleDisableVPN(custom, interaction: interaction)
} else if let custom = interaction.intent as? MoveToLocationIntent {
handleMoveToLocation(custom, interaction: interaction)
} else if let _ = interaction.intent as? TrustCurrentNetworkIntent {
handleCurrentNetwork(trust: true, interaction: interaction)
} else if let _ = interaction.intent as? UntrustCurrentNetworkIntent {
handleCurrentNetwork(trust: false, interaction: interaction)
} else if let _ = interaction.intent as? TrustCellularNetworkIntent {
handleCellularNetwork(trust: true, interaction: interaction)
} else if let _ = interaction.intent as? UntrustCellularNetworkIntent {
handleCellularNetwork(trust: false, interaction: interaction)
public static func handleInteraction(_ interaction: INInteraction, completionHandler: ((Error?) -> Void)?) {
handleIntent(interaction.intent, interaction: interaction, completionHandler: completionHandler)
}
public static func handleIntent(_ intent: INIntent, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
if let custom = intent as? ConnectVPNIntent {
handleConnectVPN(custom, interaction: interaction, completionHandler: completionHandler)
} else if let custom = intent as? EnableVPNIntent {
handleEnableVPN(custom, interaction: interaction, completionHandler: completionHandler)
} else if let custom = intent as? DisableVPNIntent {
handleDisableVPN(custom, interaction: interaction, completionHandler: completionHandler)
} else if let custom = intent as? MoveToLocationIntent {
handleMoveToLocation(custom, interaction: interaction, completionHandler: completionHandler)
} else if let _ = intent as? TrustCurrentNetworkIntent {
handleCurrentNetwork(trust: true, interaction: interaction, completionHandler: completionHandler)
} else if let _ = intent as? UntrustCurrentNetworkIntent {
handleCurrentNetwork(trust: false, interaction: interaction, completionHandler: completionHandler)
} else if let _ = intent as? TrustCellularNetworkIntent {
handleCellularNetwork(trust: true, interaction: interaction, completionHandler: completionHandler)
} else if let _ = intent as? UntrustCellularNetworkIntent {
handleCellularNetwork(trust: false, interaction: interaction, completionHandler: completionHandler)
}
}
private static func handleConnectVPN(_ intent: ConnectVPNIntent, interaction: INInteraction) {
public static func handleConnectVPN(_ intent: ConnectVPNIntent, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
guard let contextValue = intent.context, let context = Context(rawValue: contextValue), let id = intent.profileId else {
INInteraction.delete(with: [interaction.identifier], completion: nil)
if let interactionIdentifier = interaction?.identifier {
INInteraction.delete(with: [interactionIdentifier], completion: nil)
}
// FIXME: error = missing data, programming error
completionHandler?(nil)
return
}
let profileKey = ProfileKey(context, id)
@ -146,22 +153,29 @@ class InteractionsHandler {
let vpn = VPN.shared
guard !(service.isActiveProfile(profileKey) && (vpn.status == .connected)) else {
log.info("Profile is already active and connected")
completionHandler?(nil)
return
}
guard let profile = service.profile(withContext: context, id: id) else {
// FIXME: error = no profile
completionHandler?(nil)
return
}
service.activateProfile(profile)
refreshVPN(service: service, doReconnect: true)
refreshVPN(service: service, doReconnect: true, completionHandler: completionHandler)
}
private static func handleMoveToLocation(_ intent: MoveToLocationIntent, interaction: INInteraction) {
public static func handleMoveToLocation(_ intent: MoveToLocationIntent, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
guard let providerId = intent.providerId, let poolId = intent.poolId else {
// FIXME: error = no provider/pool
completionHandler?(nil)
return
}
let service = TransientStore.shared.service
guard let providerProfile = service.profile(withContext: .provider, id: providerId) as? ProviderConnectionProfile else {
// FIXME: error = no provider
completionHandler?(nil)
return
}
log.info("Move to provider location: \(providerId) @ [\(poolId)]")
@ -169,29 +183,33 @@ class InteractionsHandler {
let vpn = VPN.shared
guard !(service.isActiveProfile(providerProfile) && (providerProfile.poolId == poolId) && (vpn.status == .connected)) else {
log.info("Profile is already active and connected to \(poolId)")
completionHandler?(nil)
return
}
providerProfile.poolId = poolId
service.activateProfile(providerProfile)
refreshVPN(service: service, doReconnect: true)
refreshVPN(service: service, doReconnect: true, completionHandler: completionHandler)
}
private static func handleEnableVPN(_ intent: EnableVPNIntent, interaction: INInteraction) {
public static func handleEnableVPN(_ intent: EnableVPNIntent, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
let service = TransientStore.shared.service
log.info("Enabling VPN...")
refreshVPN(service: service, doReconnect: true)
refreshVPN(service: service, doReconnect: true, completionHandler: completionHandler)
}
private static func handleDisableVPN(_ intent: DisableVPNIntent, interaction: INInteraction) {
public static func handleDisableVPN(_ intent: DisableVPNIntent, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
log.info("Disabling VPN...")
VPN.shared.disconnect { (error) in
notifyServiceController()
notifyServiceUpdate()
completionHandler?(error)
}
}
private static func handleCurrentNetwork(trust: Bool, interaction: INInteraction) {
public static func handleCurrentNetwork(trust: Bool, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
guard let currentWifi = Utils.currentWifiNetworkName() else {
// FIXME: error = not connected to wifi
completionHandler?(nil)
return
}
let service = TransientStore.shared.service
@ -199,11 +217,13 @@ class InteractionsHandler {
TransientStore.shared.serialize(withProfiles: false)
log.info("\(trust ? "Trusted" : "Untrusted") Wi-Fi: \(currentWifi)")
refreshVPN(service: service, doReconnect: false)
refreshVPN(service: service, doReconnect: false, completionHandler: completionHandler)
}
private static func handleCellularNetwork(trust: Bool, interaction: INInteraction) {
public static func handleCellularNetwork(trust: Bool, interaction: INInteraction?, completionHandler: ((Error?) -> Void)?) {
guard Utils.hasCellularData() else {
// FIXME: error = has no mobile data
completionHandler?(nil)
return
}
let service = TransientStore.shared.service
@ -211,16 +231,17 @@ class InteractionsHandler {
TransientStore.shared.serialize(withProfiles: false)
log.info("\(trust ? "Trusted" : "Untrusted") cellular network")
refreshVPN(service: service, doReconnect: false)
refreshVPN(service: service, doReconnect: false, completionHandler: completionHandler)
}
private static func refreshVPN(service: ConnectionService, doReconnect: Bool) {
private static func refreshVPN(service: ConnectionService, doReconnect: Bool, completionHandler: ((Error?) -> Void)?) {
let configuration: VPNConfiguration
do {
configuration = try service.vpnConfiguration()
} catch let e {
log.error("Unable to build VPN configuration: \(e)")
notifyServiceController()
notifyServiceUpdate()
completionHandler?(e)
return
}
@ -228,19 +249,21 @@ class InteractionsHandler {
if doReconnect {
log.info("Reconnecting VPN: \(configuration)")
vpn.reconnect(configuration: configuration) { (error) in
notifyServiceController()
notifyServiceUpdate()
completionHandler?(error)
}
} else {
log.info("Reinstalling VPN: \(configuration)")
vpn.install(configuration: configuration) { (error) in
notifyServiceController()
notifyServiceUpdate()
completionHandler?(error)
}
}
}
//
static func forgetProfile(withKey profileKey: ProfileKey) {
public static func forgetProfile(withKey profileKey: ProfileKey) {
INInteraction.delete(with: profileKey.rawValue) { (error) in
if let error = error {
log.error("Unable to forget interactions: \(error)")
@ -252,7 +275,7 @@ class InteractionsHandler {
//
private static func notifyServiceController() {
private static func notifyServiceUpdate() {
NotificationCenter.default.post(name: .IntentDidUpdateService, object: nil)
}
}

View File

@ -7,7 +7,7 @@
<key>INIntentDefinitionModelVersion</key>
<string>1.0</string>
<key>INIntentDefinitionSystemVersion</key>
<string>17G3025</string>
<string>18D42</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>10B61</string>
<key>INIntentDefinitionToolsVersion</key>
@ -74,7 +74,7 @@
<array>
<dict>
<key>INIntentResponseCodeFormatString</key>
<string>Unable to connect</string>
<string></string>
<key>INIntentResponseCodeFormatStringID</key>
<string>uKU9RD</string>
<key>INIntentResponseCodeName</key>
@ -84,7 +84,7 @@
</dict>
<dict>
<key>INIntentResponseCodeFormatString</key>
<string>Successfully connected!</string>
<string></string>
<key>INIntentResponseCodeFormatStringID</key>
<string>WNbRl5</string>
<key>INIntentResponseCodeName</key>