Implement BuildPeerConfigurationUpdate App Intent
Signed-off-by: Alessio Nossa <alessio.nossa@gmail.com>
This commit is contained in:
@@ -10,3 +10,15 @@
|
|||||||
"getPeersIntentDescription" = "Get list of public keys of peers in the selected configuration";
|
"getPeersIntentDescription" = "Get list of public keys of peers in the selected configuration";
|
||||||
"getPeersIntentTunnelParameterTitle" = "Tunnel";
|
"getPeersIntentTunnelParameterTitle" = "Tunnel";
|
||||||
"getPeersIntentSummary ${tunnelName}" = "Get peers of ${tunnelName}";
|
"getPeersIntentSummary ${tunnelName}" = "Get peers of ${tunnelName}";
|
||||||
|
|
||||||
|
// Build Peer Configuration
|
||||||
|
"buildPeerConfigurationUpdateIntentName" = "Build Peer Configuration";
|
||||||
|
"buildPeerConfigurationUpdateIntentDescription" = "";
|
||||||
|
"buildPeerConfigurationUpdateIntentSummary ${publicKey}" = "Build configuration for peer ${publicKey}";
|
||||||
|
"buildPeerConfigurationUpdateIntentPublicKeyParameterTitle" = "Peer Public Key";
|
||||||
|
"buildPeerConfigurationUpdateIntentEndpointParameterTitle" = "Endpoint";
|
||||||
|
|
||||||
|
// Peer Configuration Update Entity
|
||||||
|
"peerConfigurationUpdateEntityName" = "Configuration Update - Peer";
|
||||||
|
"peerConfigurationUpdateEntityPropertyPublicKeyTitle" = "Public Key";
|
||||||
|
"peerConfigurationUpdateEntityPropertyEndpointTitle" = "Endpoint";
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
|
import AppIntents
|
||||||
|
|
||||||
|
let kEndpointConfigurationUpdateDictionaryKey = "Endpoint"
|
||||||
|
|
||||||
|
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
|
||||||
|
struct BuildPeerConfigurationUpdate: AppIntent {
|
||||||
|
|
||||||
|
static var title = LocalizedStringResource("buildPeerConfigurationUpdateIntentName", table: "AppIntents")
|
||||||
|
static var description = IntentDescription(
|
||||||
|
LocalizedStringResource("buildPeerConfigurationUpdateIntentDescription", table: "AppIntents")
|
||||||
|
)
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
title: LocalizedStringResource("buildPeerConfigurationUpdateIntentPublicKeyParameterTitle", table: "AppIntents")
|
||||||
|
)
|
||||||
|
var publicKey: String
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
title: LocalizedStringResource("buildPeerConfigurationUpdateIntentEndpointParameterTitle", table: "AppIntents")
|
||||||
|
)
|
||||||
|
var endpoint: String
|
||||||
|
|
||||||
|
func perform() async throws -> some IntentResult {
|
||||||
|
let peerConfigurationUpdate = AppIntentsPeer()
|
||||||
|
peerConfigurationUpdate.publicKey = publicKey
|
||||||
|
peerConfigurationUpdate.endpoint = endpoint
|
||||||
|
|
||||||
|
return .result(value: peerConfigurationUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
|
static var parameterSummary: some ParameterSummary {
|
||||||
|
Summary("buildPeerConfigurationUpdateIntentSummary \(\.$publicKey)", table: "AppIntents") {
|
||||||
|
\.$endpoint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
|
||||||
|
struct AppIntentsPeer: TransientAppEntity {
|
||||||
|
|
||||||
|
static var typeDisplayRepresentation = TypeDisplayRepresentation(
|
||||||
|
name: LocalizedStringResource("peerConfigurationUpdateEntityName", table: "AppIntents")
|
||||||
|
)
|
||||||
|
|
||||||
|
@Property(
|
||||||
|
title: LocalizedStringResource("peerConfigurationUpdateEntityPropertyPublicKeyTitle", table: "AppIntents")
|
||||||
|
)
|
||||||
|
var publicKey: String
|
||||||
|
|
||||||
|
@Property(
|
||||||
|
title: LocalizedStringResource("peerConfigurationUpdateEntityPropertyEndpointTitle", table: "AppIntents")
|
||||||
|
)
|
||||||
|
var endpoint: String?
|
||||||
|
|
||||||
|
var displayRepresentation: DisplayRepresentation {
|
||||||
|
var dictionary: [String: [String: String]] = [:]
|
||||||
|
dictionary[publicKey] = [:]
|
||||||
|
|
||||||
|
if let endpoint {
|
||||||
|
dictionary[publicKey]?.updateValue(endpoint, forKey: kEndpointConfigurationUpdateDictionaryKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
let jsonData: Data
|
||||||
|
do {
|
||||||
|
jsonData = try JSONSerialization.data(withJSONObject: dictionary)
|
||||||
|
} catch {
|
||||||
|
return DisplayRepresentation(stringLiteral: error.localizedDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
let jsonString = String(data: jsonData, encoding: .utf8)!
|
||||||
|
|
||||||
|
return DisplayRepresentation(stringLiteral: jsonString)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -207,6 +207,7 @@
|
|||||||
6FFACD2021E4D8D500E9A2A5 /* ParseError+WireGuardAppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFACD1E21E4D89600E9A2A5 /* ParseError+WireGuardAppError.swift */; };
|
6FFACD2021E4D8D500E9A2A5 /* ParseError+WireGuardAppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FFACD1E21E4D89600E9A2A5 /* ParseError+WireGuardAppError.swift */; };
|
||||||
A625F05529C4C627005EF23D /* GetPeers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A625F05029C4C627005EF23D /* GetPeers.swift */; };
|
A625F05529C4C627005EF23D /* GetPeers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A625F05029C4C627005EF23D /* GetPeers.swift */; };
|
||||||
A6E361F829D8758500FFF234 /* AppIntents.strings in Resources */ = {isa = PBXBuildFile; fileRef = A6E361F729D8758500FFF234 /* AppIntents.strings */; };
|
A6E361F829D8758500FFF234 /* AppIntents.strings in Resources */ = {isa = PBXBuildFile; fileRef = A6E361F729D8758500FFF234 /* AppIntents.strings */; };
|
||||||
|
A6E361FC29D9AEEA00FFF234 /* BuildPeerConfigurationUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E361FB29D9AEEA00FFF234 /* BuildPeerConfigurationUpdate.swift */; };
|
||||||
A6E361FE29D9B18C00FFF234 /* TunnelsOptionsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E361FD29D9B18C00FFF234 /* TunnelsOptionsProvider.swift */; };
|
A6E361FE29D9B18C00FFF234 /* TunnelsOptionsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E361FD29D9B18C00FFF234 /* TunnelsOptionsProvider.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
@@ -443,6 +444,7 @@
|
|||||||
6FFACD1E21E4D89600E9A2A5 /* ParseError+WireGuardAppError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ParseError+WireGuardAppError.swift"; sourceTree = "<group>"; };
|
6FFACD1E21E4D89600E9A2A5 /* ParseError+WireGuardAppError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ParseError+WireGuardAppError.swift"; sourceTree = "<group>"; };
|
||||||
A625F05029C4C627005EF23D /* GetPeers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetPeers.swift; sourceTree = "<group>"; };
|
A625F05029C4C627005EF23D /* GetPeers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetPeers.swift; sourceTree = "<group>"; };
|
||||||
A6E361F729D8758500FFF234 /* AppIntents.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = AppIntents.strings; sourceTree = "<group>"; };
|
A6E361F729D8758500FFF234 /* AppIntents.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = AppIntents.strings; sourceTree = "<group>"; };
|
||||||
|
A6E361FB29D9AEEA00FFF234 /* BuildPeerConfigurationUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildPeerConfigurationUpdate.swift; sourceTree = "<group>"; };
|
||||||
A6E361FD29D9B18C00FFF234 /* TunnelsOptionsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelsOptionsProvider.swift; sourceTree = "<group>"; };
|
A6E361FD29D9B18C00FFF234 /* TunnelsOptionsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelsOptionsProvider.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
@@ -821,6 +823,7 @@
|
|||||||
A625F04C29C4C627005EF23D /* WireguardAppIntents */ = {
|
A625F04C29C4C627005EF23D /* WireguardAppIntents */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
A6E361FB29D9AEEA00FFF234 /* BuildPeerConfigurationUpdate.swift */,
|
||||||
A625F05029C4C627005EF23D /* GetPeers.swift */,
|
A625F05029C4C627005EF23D /* GetPeers.swift */,
|
||||||
A6E361F729D8758500FFF234 /* AppIntents.strings */,
|
A6E361F729D8758500FFF234 /* AppIntents.strings */,
|
||||||
A6E361FD29D9B18C00FFF234 /* TunnelsOptionsProvider.swift */,
|
A6E361FD29D9B18C00FFF234 /* TunnelsOptionsProvider.swift */,
|
||||||
@@ -1456,6 +1459,7 @@
|
|||||||
6F919EC3218A2AE90023B400 /* ErrorPresenter.swift in Sources */,
|
6F919EC3218A2AE90023B400 /* ErrorPresenter.swift in Sources */,
|
||||||
6B62E45F220A6FA900EF34A6 /* PrivateDataConfirmation.swift in Sources */,
|
6B62E45F220A6FA900EF34A6 /* PrivateDataConfirmation.swift in Sources */,
|
||||||
6F5A2B4821AFF49A0081EDD8 /* FileManager+Extension.swift in Sources */,
|
6F5A2B4821AFF49A0081EDD8 /* FileManager+Extension.swift in Sources */,
|
||||||
|
A6E361FC29D9AEEA00FFF234 /* BuildPeerConfigurationUpdate.swift in Sources */,
|
||||||
5F45418C21C2D48200994C13 /* TunnelEditKeyValueCell.swift in Sources */,
|
5F45418C21C2D48200994C13 /* TunnelEditKeyValueCell.swift in Sources */,
|
||||||
6FE254FB219C10800028284D /* ZipImporter.swift in Sources */,
|
6FE254FB219C10800028284D /* ZipImporter.swift in Sources */,
|
||||||
585B107E2577E294004F691E /* PrivateKey.swift in Sources */,
|
585B107E2577E294004F691E /* PrivateKey.swift in Sources */,
|
||||||
|
|||||||
Reference in New Issue
Block a user