Skip to content

Commit 40ee8a7

Browse files
committed
fix(ui): SSH connections in welcome list show database target with SSH badge
1 parent 1d338f0 commit 40ee8a7

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

TablePro/Views/Connection/WelcomeConnectionRow.swift

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ struct WelcomeConnectionRow: View {
5656
.help(String(localized: "Bundled sample database"))
5757
}
5858

59+
if connection.resolvedSSHConfig.enabled {
60+
Image(systemName: "lock.shield")
61+
.font(.system(size: 10))
62+
.foregroundStyle(.secondary)
63+
.help(sshTunnelTooltip)
64+
.accessibilityLabel(String(localized: "SSH tunnel"))
65+
}
66+
5967
if connection.localOnly && !connection.isSample {
6068
Image(systemName: "icloud.slash")
6169
.font(.system(size: 9))
@@ -81,20 +89,36 @@ struct WelcomeConnectionRow: View {
8189
}
8290

8391
private var connectionSubtitle: String {
84-
let ssh = connection.resolvedSSHConfig
85-
if ssh.enabled {
86-
return "SSH : \(ssh.username)@\(ssh.host)"
87-
}
8892
if connection.host.isEmpty {
8993
return connection.database.isEmpty ? connection.type.rawValue : connection.database
9094
}
9195
if let mongoHosts = connection.additionalFields["mongoHosts"], mongoHosts.contains(",") {
9296
let count = mongoHosts.split(separator: ",").count
9397
return String(
9498
format: String(localized: "%@ (+%d more)"),
95-
"\(connection.host):\(connection.port)", count - 1
99+
hostWithOptionalPort, count - 1
96100
)
97101
}
98-
return connection.host
102+
return hostWithOptionalPort
103+
}
104+
105+
private var hostWithOptionalPort: String {
106+
if connection.port == connection.type.defaultPort {
107+
return connection.host
108+
}
109+
return "\(connection.host):\(connection.port)"
110+
}
111+
112+
private var sshTunnelTooltip: String {
113+
let ssh = connection.resolvedSSHConfig
114+
let userPrefix = ssh.username.isEmpty ? "" : "\(ssh.username)@"
115+
let portSuffix: String
116+
if let port = ssh.port, port != 22 {
117+
portSuffix = ":\(port)"
118+
} else {
119+
portSuffix = ""
120+
}
121+
let target = "\(userPrefix)\(ssh.host)\(portSuffix)"
122+
return String(format: String(localized: "Connects via SSH tunnel: %@"), target)
99123
}
100124
}

0 commit comments

Comments
 (0)