WireguardApp: iOS: Added Siri shortcuts donations for SetTunnelStatus intent

Signed-off-by: Alessio Nossa <alessio.nossa@gmail.com>
This commit is contained in:
Alessio Nossa
2022-02-01 17:51:18 +01:00
parent bb6ea1b2f3
commit c29787f898
4 changed files with 53 additions and 0 deletions
@@ -2,6 +2,7 @@
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
import UIKit
import Intents
class TunnelDetailTableViewController: UITableViewController {
@@ -387,6 +388,18 @@ extension TunnelDetailTableViewController {
cell.onSwitchToggled = { [weak self] isOn in
guard let self = self else { return }
let intent = SetTunnelStatusIntent()
intent.tunnel = self.tunnel.name
intent.operation = .turn
intent.state = isOn ? .on : .off
let interaction = INInteraction(intent: intent, response: nil)
interaction.groupIdentifier = "com.wireguard.intents.tunnel.\(self.tunnel.name)"
interaction.donate { error in
if let error = error {
wg_log(.error, message: "Error donating interaction for SetTunnelStatusIntent: \(error.localizedDescription)")
}
}
if self.tunnel.hasOnDemandRules {
self.tunnelsManager.setOnDemandEnabled(isOn, on: self.tunnel) { error in
if error == nil && !isOn {