Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TablePro/Core/Storage/SSHProfileStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class SSHProfileStorage {
private let defaults = UserDefaults.standard
private let encoder = JSONEncoder()
private let decoder = JSONDecoder()
private var lastLoadFailed = false
private(set) var lastLoadFailed = false

private init() {}

Expand Down
5 changes: 5 additions & 0 deletions TablePro/Core/Sync/SyncRecordMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct SyncRecordMapper {
if let startupCommands = connection.startupCommands {
record["startupCommands"] = startupCommands as CKRecordValue
}
if let sshProfileId = connection.sshProfileId {
record["sshProfileId"] = sshProfileId.uuidString as CKRecordValue
}

// Encode complex structs as JSON Data
do {
Expand Down Expand Up @@ -130,6 +133,7 @@ struct SyncRecordMapper {
let aiPolicyRaw = record["aiPolicy"] as? String
let redisDatabase = (record["redisDatabase"] as? Int64).map { Int($0) }
let startupCommands = record["startupCommands"] as? String
let sshProfileId = (record["sshProfileId"] as? String).flatMap { UUID(uuidString: $0) }

var sshConfig = SSHConfiguration()
if let sshData = record["sshConfigJson"] as? Data {
Expand Down Expand Up @@ -159,6 +163,7 @@ struct SyncRecordMapper {
color: ConnectionColor(rawValue: colorRaw) ?? .none,
tagId: tagId,
groupId: groupId,
sshProfileId: sshProfileId,
safeModeLevel: SafeModeLevel(rawValue: safeModeLevelRaw) ?? .silent,
aiPolicy: aiPolicyRaw.flatMap { AIConnectionPolicy(rawValue: $0) },
redisDatabase: redisDatabase,
Expand Down
5 changes: 1 addition & 4 deletions TablePro/Models/Connection/ConnectionGroupTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

enum ConnectionGroupTreeNode: Identifiable, Hashable {
enum ConnectionGroupTreeNode: Identifiable {
case group(ConnectionGroup, children: [ConnectionGroupTreeNode])
case connection(DatabaseConnection)

Expand All @@ -15,9 +15,6 @@ enum ConnectionGroupTreeNode: Identifiable, Hashable {
case .connection(let c): "conn-\(c.id)"
}
}

static func == (lhs: Self, rhs: Self) -> Bool { lhs.id == rhs.id }
func hash(into hasher: inout Hasher) { hasher.combine(id) }
}

// MARK: - Tree Building
Expand Down
41 changes: 24 additions & 17 deletions TablePro/Views/Connection/ConnectionFormView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,9 @@ struct ConnectionFormView: View { // swiftlint:disable:this type_body_length

private func reloadProfiles() {
sshProfiles = SSHProfileStorage.shared.loadProfiles()
// If the edited/deleted profile no longer exists, clear the selection
if let id = sshProfileId, !sshProfiles.contains(where: { $0.id == id }) {
if let id = sshProfileId,
!SSHProfileStorage.shared.lastLoadFailed,
!sshProfiles.contains(where: { $0.id == id }) {
sshProfileId = nil
}
}
Expand Down Expand Up @@ -1176,21 +1177,27 @@ struct ConnectionFormView: View { // swiftlint:disable:this type_body_length
}

private func saveConnection() {
let sshConfig = SSHConfiguration(
enabled: sshEnabled,
host: sshHost,
port: Int(sshPort) ?? 22,
username: sshUsername,
authMethod: sshAuthMethod,
privateKeyPath: sshPrivateKeyPath,
useSSHConfig: !selectedSSHConfigHost.isEmpty,
agentSocketPath: resolvedSSHAgentSocketPath,
jumpHosts: jumpHosts,
totpMode: totpMode,
totpAlgorithm: totpAlgorithm,
totpDigits: totpDigits,
totpPeriod: totpPeriod
)
let sshConfig: SSHConfiguration
if let profileId = sshProfileId,
let profile = sshProfiles.first(where: { $0.id == profileId }) {
sshConfig = profile.toSSHConfiguration()
} else {
sshConfig = SSHConfiguration(
enabled: sshEnabled,
host: sshHost,
port: Int(sshPort) ?? 22,
username: sshUsername,
authMethod: sshAuthMethod,
privateKeyPath: sshPrivateKeyPath,
useSSHConfig: !selectedSSHConfigHost.isEmpty,
agentSocketPath: resolvedSSHAgentSocketPath,
jumpHosts: jumpHosts,
totpMode: totpMode,
totpAlgorithm: totpAlgorithm,
totpDigits: totpDigits,
totpPeriod: totpPeriod
)
}

let sslConfig = SSLConfiguration(
mode: sslMode,
Expand Down
Loading