Add EnableVPN intent

This commit is contained in:
Davide De Rosa 2019-03-10 14:03:39 +01:00
parent 9dcd6de873
commit ab500cccb0
3 changed files with 91 additions and 0 deletions

View File

@ -47,6 +47,7 @@
<array> <array>
<string>ConnectVPNIntent</string> <string>ConnectVPNIntent</string>
<string>DisableVPNIntent</string> <string>DisableVPNIntent</string>
<string>EnableVPNIntent</string>
<string>MoveToLocationIntent</string> <string>MoveToLocationIntent</string>
<string>TrustCellularNetworkIntent</string> <string>TrustCellularNetworkIntent</string>
<string>TrustCurrentNetworkIntent</string> <string>TrustCurrentNetworkIntent</string>

View File

@ -63,6 +63,14 @@ class InteractionsHandler {
interaction.donateAndLog() interaction.donateAndLog()
} }
static func donateEnableVPN() {
let intent = EnableVPNIntent()
let interaction = INInteraction(intent: intent, response: nil)
interaction.groupIdentifier = Groups.vpn
interaction.donateAndLog()
}
static func donateDisableVPN() { static func donateDisableVPN() {
let intent = DisableVPNIntent() let intent = DisableVPNIntent()
@ -108,6 +116,8 @@ class InteractionsHandler {
static func handleInteraction(_ interaction: INInteraction) { static func handleInteraction(_ interaction: INInteraction) {
if let custom = interaction.intent as? ConnectVPNIntent { if let custom = interaction.intent as? ConnectVPNIntent {
handleConnectVPN(custom, interaction: interaction) handleConnectVPN(custom, interaction: interaction)
} else if let custom = interaction.intent as? EnableVPNIntent {
handleEnableVPN(custom, interaction: interaction)
} else if let custom = interaction.intent as? DisableVPNIntent { } else if let custom = interaction.intent as? DisableVPNIntent {
handleDisableVPN(custom, interaction: interaction) handleDisableVPN(custom, interaction: interaction)
} else if let custom = interaction.intent as? MoveToLocationIntent { } else if let custom = interaction.intent as? MoveToLocationIntent {
@ -166,6 +176,12 @@ class InteractionsHandler {
refreshVPN(service: service, doReconnect: true) 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) { private static func handleDisableVPN(_ intent: DisableVPNIntent, interaction: INInteraction) {
VPN.shared.disconnect { (error) in VPN.shared.disconnect { (error) in
notifyServiceController() notifyServiceController()

View File

@ -580,6 +580,80 @@
<key>INIntentVerb</key> <key>INIntentVerb</key>
<string>Go</string> <string>Go</string>
</dict> </dict>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentDescription</key>
<string>With currently active profile</string>
<key>INIntentDescriptionID</key>
<string>xY97Vu</string>
<key>INIntentLastParameterTag</key>
<integer>0</integer>
<key>INIntentName</key>
<string>EnableVPN</string>
<key>INIntentParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSubtitle</key>
<string></string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>NCoK9B</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string></string>
<key>INIntentParameterCombinationTitleID</key>
<string>yesvFP</string>
</dict>
</dict>
<key>INIntentParameters</key>
<array/>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeFormatString</key>
<string></string>
<key>INIntentResponseCodeFormatStringID</key>
<string>FJp18d</string>
<key>INIntentResponseCodeName</key>
<string>failure</string>
<key>INIntentResponseCodeSuccess</key>
<false/>
</dict>
<dict>
<key>INIntentResponseCodeFormatString</key>
<string></string>
<key>INIntentResponseCodeFormatStringID</key>
<string>lV5LVw</string>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
</array>
<key>INIntentResponseLastParameterTag</key>
<integer>0</integer>
<key>INIntentResponseParameters</key>
<array/>
</dict>
<key>INIntentRestrictions</key>
<integer>0</integer>
<key>INIntentTitle</key>
<string>Enable VPN service</string>
<key>INIntentTitleID</key>
<string>lQ6ziK</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentUserConfirmationRequired</key>
<false/>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array> </array>
</dict> </dict>
</plist> </plist>