Remove GetPeers SiriKit Intent
Signed-off-by: Alessio Nossa <alessio.nossa@gmail.com>
This commit is contained in:
@@ -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)")
|
||||
}
|
||||
|
||||
|
||||
@@ -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<NSString>?, 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 {
|
||||
|
||||
Reference in New Issue
Block a user