From ab500cccb005a7835dee2899ceacd5d538e7a5f6 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 10 Mar 2019 14:03:39 +0100 Subject: [PATCH] Add EnableVPN intent --- Passepartout-iOS/Info.plist | 1 + .../Intents/InteractionsHandler.swift | 16 ++++ .../Intents/en.lproj/Intents.intentdefinition | 74 +++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/Passepartout-iOS/Info.plist b/Passepartout-iOS/Info.plist index 6e4d51c0..37525d17 100644 --- a/Passepartout-iOS/Info.plist +++ b/Passepartout-iOS/Info.plist @@ -47,6 +47,7 @@ ConnectVPNIntent DisableVPNIntent + EnableVPNIntent MoveToLocationIntent TrustCellularNetworkIntent TrustCurrentNetworkIntent diff --git a/Passepartout-iOS/Intents/InteractionsHandler.swift b/Passepartout-iOS/Intents/InteractionsHandler.swift index da31a51f..2d386e9b 100644 --- a/Passepartout-iOS/Intents/InteractionsHandler.swift +++ b/Passepartout-iOS/Intents/InteractionsHandler.swift @@ -63,6 +63,14 @@ class InteractionsHandler { interaction.donateAndLog() } + static func donateEnableVPN() { + let intent = EnableVPNIntent() + + let interaction = INInteraction(intent: intent, response: nil) + interaction.groupIdentifier = Groups.vpn + interaction.donateAndLog() + } + static func donateDisableVPN() { let intent = DisableVPNIntent() @@ -108,6 +116,8 @@ 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 { @@ -166,6 +176,12 @@ class InteractionsHandler { refreshVPN(service: service, doReconnect: true) } + private static func handleEnableVPN(_ intent: EnableVPNIntent, interaction: INInteraction) { + let service = TransientStore.shared.service + log.info("Enabling VPN...") + refreshVPN(service: service, doReconnect: true) + } + private static func handleDisableVPN(_ intent: DisableVPNIntent, interaction: INInteraction) { VPN.shared.disconnect { (error) in notifyServiceController() diff --git a/Passepartout-iOS/Intents/en.lproj/Intents.intentdefinition b/Passepartout-iOS/Intents/en.lproj/Intents.intentdefinition index 48424644..e319b4fd 100644 --- a/Passepartout-iOS/Intents/en.lproj/Intents.intentdefinition +++ b/Passepartout-iOS/Intents/en.lproj/Intents.intentdefinition @@ -580,6 +580,80 @@ INIntentVerb Go + + INIntentCategory + generic + INIntentDescription + With currently active profile + INIntentDescriptionID + xY97Vu + INIntentLastParameterTag + 0 + INIntentName + EnableVPN + INIntentParameterCombinations + + + + INIntentParameterCombinationIsPrimary + + INIntentParameterCombinationSubtitle + + INIntentParameterCombinationSubtitleID + NCoK9B + INIntentParameterCombinationSupportsBackgroundExecution + + INIntentParameterCombinationTitle + + INIntentParameterCombinationTitleID + yesvFP + + + INIntentParameters + + INIntentResponse + + INIntentResponseCodes + + + INIntentResponseCodeFormatString + + INIntentResponseCodeFormatStringID + FJp18d + INIntentResponseCodeName + failure + INIntentResponseCodeSuccess + + + + INIntentResponseCodeFormatString + + INIntentResponseCodeFormatStringID + lV5LVw + INIntentResponseCodeName + success + INIntentResponseCodeSuccess + + + + INIntentResponseLastParameterTag + 0 + INIntentResponseParameters + + + INIntentRestrictions + 0 + INIntentTitle + Enable VPN service + INIntentTitleID + lQ6ziK + INIntentType + Custom + INIntentUserConfirmationRequired + + INIntentVerb + Do +