Removed UpdateConfigurationIntent SiriKit Intent

Signed-off-by: Alessio Nossa <alessio.nossa@gmail.com>
This commit is contained in:
Alessio Nossa
2023-04-05 15:40:51 +02:00
parent bee5d346b1
commit d05a1693e2
6 changed files with 3 additions and 418 deletions
@@ -115,88 +115,6 @@ extension AppDelegate {
extension AppDelegate {
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard let interaction = userActivity.interaction else {
return false
}
if interaction.intent is UpdateConfigurationIntent {
if let tunnelsManager = tunnelsManager {
self.handleupdateConfigurationIntent(interaction: interaction, tunnelsManager: tunnelsManager)
} else {
var token: NSObjectProtocol?
token = NotificationCenter.default.addObserver(forName: AppDelegate.tunnelsManagerReadyNotificationName, object: nil, queue: .main) { [weak self] _ in
guard let tunnelsManager = self?.tunnelsManager else { return }
self?.handleupdateConfigurationIntent(interaction: interaction, tunnelsManager: tunnelsManager)
NotificationCenter.default.removeObserver(token!)
}
}
return true
}
return false
}
func handleupdateConfigurationIntent(interaction: INInteraction, tunnelsManager: TunnelsManager) {
guard let updateConfigurationIntent = interaction.intent as? UpdateConfigurationIntent,
let configurationUpdates = interaction.intentResponse?.userActivity?.userInfo else {
return
}
guard let tunnelName = updateConfigurationIntent.tunnel,
let configurations = configurationUpdates["Configuration"] as? [String: [String: String]] else {
wg_log(.error, message: "Failed to get informations to update the configuration")
return
}
guard let tunnel = tunnelsManager.tunnel(named: tunnelName),
let tunnelConfiguration = tunnel.tunnelConfiguration else {
wg_log(.error, message: "Failed to get tunnel configuration with name \(tunnelName)")
ErrorPresenter.showErrorAlert(title: "Tunnel not found",
message: "Tunnel with name '\(tunnelName)' is not present.",
from: self.mainVC)
return
}
var peers = tunnelConfiguration.peers
for (peerPubKey, valuesToUpdate) in configurations {
guard let peerIndex = peers.firstIndex(where: { $0.publicKey.base64Key == peerPubKey }) else {
wg_log(.debug, message: "Failed to find peer \(peerPubKey) in tunnel with name \(tunnelName)")
ErrorPresenter.showErrorAlert(title: "Peer not found",
message: "Peer '\(peerPubKey)' is not present in '\(tunnelName)' tunnel.",
from: self.mainVC)
continue
}
if let endpointString = valuesToUpdate["Endpoint"] {
if let newEntpoint = Endpoint(from: endpointString) {
peers[peerIndex].endpoint = newEntpoint
} else {
wg_log(.debug, message: "Failed to convert \(endpointString) to Endpoint")
}
}
}
let newConfiguration = TunnelConfiguration(name: tunnel.name, interface: tunnelConfiguration.interface, peers: peers)
tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: newConfiguration, onDemandOption: tunnel.onDemandOption) { error in
guard error == nil else {
wg_log(.error, message: error!.localizedDescription)
ErrorPresenter.showErrorAlert(error: error!, from: self.mainVC)
return
}
if let completionUrlString = updateConfigurationIntent.completionUrl,
!completionUrlString.isEmpty,
let completionUrl = URL(string: completionUrlString) {
UIApplication.shared.open(completionUrl, options: [:], completionHandler: nil)
}
wg_log(.debug, message: "Updated configuration of tunnel \(tunnelName)")
}
}
}
+1 -3
View File
@@ -83,9 +83,7 @@
<key>NSFaceIDUsageDescription</key>
<string>Localized</string>
<key>NSUserActivityTypes</key>
<array>
<string>UpdateConfigurationIntent</string>
</array>
<array/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>