iOS: copy + clean bridge address
This commit is contained in:
@@ -27,12 +27,32 @@ actor BridgeSession {
|
|||||||
private static func prettyRemoteEndpoint(_ endpoint: NWEndpoint) -> String? {
|
private static func prettyRemoteEndpoint(_ endpoint: NWEndpoint) -> String? {
|
||||||
switch endpoint {
|
switch endpoint {
|
||||||
case let .hostPort(host, port):
|
case let .hostPort(host, port):
|
||||||
"\(host):\(port)".replacingOccurrences(of: "::ffff:", with: "")
|
let hostString = Self.prettyHostString(host)
|
||||||
|
if hostString.contains(":") {
|
||||||
|
return "[\(hostString)]:\(port)"
|
||||||
|
}
|
||||||
|
return "\(hostString):\(port)"
|
||||||
default:
|
default:
|
||||||
String(describing: endpoint)
|
return String(describing: endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func prettyHostString(_ host: NWEndpoint.Host) -> String {
|
||||||
|
var hostString = String(describing: host)
|
||||||
|
hostString = hostString.replacingOccurrences(of: "::ffff:", with: "")
|
||||||
|
|
||||||
|
guard let percentIndex = hostString.firstIndex(of: "%") else { return hostString }
|
||||||
|
|
||||||
|
let prefix = hostString[..<percentIndex]
|
||||||
|
let allowed = CharacterSet(charactersIn: "0123456789abcdefABCDEF:.")
|
||||||
|
let isIPAddressPrefix = prefix.unicodeScalars.allSatisfy { allowed.contains($0) }
|
||||||
|
if isIPAddressPrefix {
|
||||||
|
return String(prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostString
|
||||||
|
}
|
||||||
|
|
||||||
func connect(
|
func connect(
|
||||||
endpoint: NWEndpoint,
|
endpoint: NWEndpoint,
|
||||||
hello: BridgeHello,
|
hello: BridgeHello,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import ClawdisKit
|
import ClawdisKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private final class ConnectStatusStore: ObservableObject {
|
private final class ConnectStatusStore: ObservableObject {
|
||||||
@@ -43,7 +44,16 @@ struct SettingsTab: View {
|
|||||||
if let serverName = self.appModel.bridgeServerName {
|
if let serverName = self.appModel.bridgeServerName {
|
||||||
LabeledContent("Server", value: serverName)
|
LabeledContent("Server", value: serverName)
|
||||||
if let addr = self.appModel.bridgeRemoteAddress {
|
if let addr = self.appModel.bridgeRemoteAddress {
|
||||||
LabeledContent("Address", value: addr)
|
LabeledContent("Address") {
|
||||||
|
Text(addr)
|
||||||
|
}
|
||||||
|
.contextMenu {
|
||||||
|
Button {
|
||||||
|
UIPasteboard.general.string = addr
|
||||||
|
} label: {
|
||||||
|
Label("Copy", systemImage: "doc.on.doc")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button("Disconnect", role: .destructive) {
|
Button("Disconnect", role: .destructive) {
|
||||||
|
|||||||
Reference in New Issue
Block a user