From: Alessio Nossa Date: Wed, 5 Apr 2023 11:30:40 +0000 (+0200) Subject: Remove GetPeers SiriKit Intent X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29522061388daa4742985e91495ce555c01598aa;p=thirdparty%2Fwireguard-apple.git Remove GetPeers SiriKit Intent Signed-off-by: Alessio Nossa --- diff --git a/Sources/Shared/Intents.intentdefinition b/Sources/Shared/Intents.intentdefinition index 8c8d33b..97b2595 100644 --- a/Sources/Shared/Intents.intentdefinition +++ b/Sources/Shared/Intents.intentdefinition @@ -16,140 +16,6 @@ 14.2 INIntents - - INIntentCategory - generic - INIntentConfigurable - - INIntentDescription - Get list of public keys of peers in the selected configuration - INIntentDescriptionID - e4jxYU - INIntentIneligibleForSuggestions - - INIntentKeyParameter - tunnel - INIntentLastParameterTag - 1 - INIntentManagedParameterCombinations - - tunnel - - INIntentParameterCombinationSupportsBackgroundExecution - - INIntentParameterCombinationTitle - Get peers of ${tunnel} - INIntentParameterCombinationTitleID - 5Ewt1o - INIntentParameterCombinationUpdatesLinked - - - - INIntentName - GetPeers - INIntentParameters - - - INIntentParameterConfigurable - - INIntentParameterDisplayName - Tunnel - INIntentParameterDisplayNameID - tUPuxx - INIntentParameterDisplayPriority - 1 - INIntentParameterMetadata - - INIntentParameterMetadataCapitalization - Sentences - INIntentParameterMetadataDefaultValueID - 0AfeHS - - INIntentParameterName - tunnel - INIntentParameterPromptDialogs - - - INIntentParameterPromptDialogCustom - - INIntentParameterPromptDialogType - Configuration - - - INIntentParameterPromptDialogCustom - - INIntentParameterPromptDialogType - Primary - - - INIntentParameterSupportsDynamicEnumeration - - INIntentParameterTag - 1 - INIntentParameterType - String - - - INIntentResponse - - INIntentResponseCodes - - - INIntentResponseCodeName - success - INIntentResponseCodeSuccess - - - - INIntentResponseCodeName - failure - - - INIntentResponseCodeConciseFormatString - Failed to retrive configuration with the provided name. - INIntentResponseCodeConciseFormatStringID - ExhkKO - INIntentResponseCodeFormatString - Failed to retrive configuration with the provided name. - INIntentResponseCodeFormatStringID - lxnQb0 - INIntentResponseCodeName - wrongTunnel - - - INIntentResponseLastParameterTag - 2 - INIntentResponseOutput - peersPublicKeys - INIntentResponseParameters - - - INIntentResponseParameterDisplayName - Peers Public Keys - INIntentResponseParameterDisplayNameID - zJOQgA - INIntentResponseParameterDisplayPriority - 1 - INIntentResponseParameterName - peersPublicKeys - INIntentResponseParameterSupportsMultipleValues - - INIntentResponseParameterTag - 2 - INIntentResponseParameterType - String - - - - INIntentTitle - Get Peers - INIntentTitleID - V1ySW4 - INIntentType - Custom - INIntentVerb - Do - INIntentCategory generic diff --git a/Sources/WireGuardIntentsExtension/IntentHandler.swift b/Sources/WireGuardIntentsExtension/IntentHandler.swift index a3527ef..bc85e2a 100644 --- a/Sources/WireGuardIntentsExtension/IntentHandler.swift +++ b/Sources/WireGuardIntentsExtension/IntentHandler.swift @@ -11,8 +11,7 @@ class IntentHandler: INExtension { } override func handler(for intent: INIntent) -> Any { - guard intent is GetPeersIntent || - intent is UpdateConfigurationIntent else { + guard intent is UpdateConfigurationIntent else { fatalError("Unhandled intent type: \(intent)") } diff --git a/Sources/WireGuardIntentsExtension/IntentHandling.swift b/Sources/WireGuardIntentsExtension/IntentHandling.swift index 1de3d46..461c5aa 100644 --- a/Sources/WireGuardIntentsExtension/IntentHandling.swift +++ b/Sources/WireGuardIntentsExtension/IntentHandling.swift @@ -57,66 +57,6 @@ extension IntentHandling { onTunnelsManagerReady = getTunnelsNameBlock } } - - private func allTunnelPeers(for tunnelName: String, completion: @escaping (Result<[String], IntentError>) -> Void) { - let getPeersFromConfigBlock: (TunnelsManager) -> Void = { tunnelsManager in - guard let tunnel = tunnelsManager.tunnel(named: tunnelName) else { - return completion(.failure(.wrongTunnel)) - } - - guard let publicKeys = tunnel.tunnelConfiguration?.peers.map({ $0.publicKey.base64Key }) else { - return completion(.failure(.unknown)) - } - return completion(.success(publicKeys)) - } - - if let tunnelsManager = tunnelsManager { - getPeersFromConfigBlock(tunnelsManager) - } else { - if onTunnelsManagerReady != nil { - wg_log(.error, message: "Overriding onTunnelsManagerReady action in allTunnelPeers function. This should not happen.") - } - onTunnelsManagerReady = getPeersFromConfigBlock - } - } -} - -extension IntentHandling: GetPeersIntentHandling { - - @available(iOSApplicationExtension 14.0, *) - func provideTunnelOptionsCollection(for intent: GetPeersIntent, with completion: @escaping (INObjectCollection?, Error?) -> Void) { - - self.allTunnelNames { tunnelsNames in - let tunnelsNamesObjects = (tunnelsNames ?? []).map { NSString(string: $0) } - - let objectCollection = INObjectCollection(items: tunnelsNamesObjects) - completion(objectCollection, nil) - } - } - - func handle(intent: GetPeersIntent, completion: @escaping (GetPeersIntentResponse) -> Void) { - guard let tunnel = intent.tunnel else { - return completion(GetPeersIntentResponse(code: .failure, userActivity: nil)) - } - - self.allTunnelPeers(for: tunnel) { peersResult in - switch peersResult { - case .success(let peers): - let response = GetPeersIntentResponse(code: .success, userActivity: nil) - response.peersPublicKeys = peers - completion(response) - - case .failure(let error): - switch error { - case .wrongTunnel: - completion(GetPeersIntentResponse(code: .wrongTunnel, userActivity: nil)) - default: - completion(GetPeersIntentResponse(code: .failure, userActivity: nil)) - } - } - } - } - } extension IntentHandling: UpdateConfigurationIntentHandling {