import NetworkExtension
import os.log
+#if os(iOS)
+import Intents
+#endif
+
protocol TunnelsManagerListDelegate: AnyObject {
func tunnelAdded(at index: Int)
func tunnelModified(at index: Int)
}
#elseif os(iOS)
(tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.destroyConfigurationReference()
+
+ INInteraction.delete(with: "com.wireguard.intents.tunnel.\(tunnel.name)") { error in
+ if let error = error {
+ wg_log(.error, message: "Error deleting donated interactions for tunnel \(tunnel.name): \(error.localizedDescription)")
+ }
+ }
#else
#error("Unimplemented")
#endif
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
import UIKit
+import Intents
class MainViewController: UISplitViewController {
if let tunnel = tunnelsManager.tunnel(named: tunnelName) {
tunnelsListVC.showTunnelDetail(for: tunnel, animated: false)
if shouldToggleStatus {
+
+ let intent = SetTunnelStatusIntent()
+ intent.tunnel = tunnel.name
+ intent.operation = .turn
+
if tunnel.status == .inactive {
tunnelsManager.startActivation(of: tunnel)
+ intent.state = .on
} else if tunnel.status == .active {
tunnelsManager.startDeactivation(of: tunnel)
+ intent.state = .off
+ }
+
+ let interaction = INInteraction(intent: intent, response: nil)
+ interaction.groupIdentifier = "com.wireguard.intents.tunnel.\(tunnel.name)"
+ interaction.donate { error in
+ if let error = error {
+ wg_log(.error, message: "Error donating interaction for SetTunnelStatusIntent: \(error.localizedDescription)")
+ }
}
}
}
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
import UIKit
+import Intents
class TunnelDetailTableViewController: UITableViewController {
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 {
import UIKit
import MobileCoreServices
import UserNotifications
+import Intents
class TunnelsListTableViewController: UIViewController {
cell.tunnel = tunnel
cell.onSwitchToggled = { [weak self] isOn in
guard let self = self, let tunnelsManager = self.tunnelsManager else { return }
+
+ let intent = SetTunnelStatusIntent()
+ intent.tunnel = tunnel.name
+ intent.operation = .turn
+ intent.state = isOn ? .on : .off
+ let interaction = INInteraction(intent: intent, response: nil)
+ interaction.groupIdentifier = "com.wireguard.intents.tunnel.\(tunnel.name)"
+ interaction.donate { error in
+ if let error = error {
+ wg_log(.error, message: "Error donating interaction for SetTunnelStatusIntent: \(error.localizedDescription)")
+ }
+ }
+
if tunnel.hasOnDemandRules {
tunnelsManager.setOnDemandEnabled(isOn, on: tunnel) { error in
if error == nil && !isOn {