@@ -49,11 +49,19 @@ struct SSHProfileEditorView: View {
4949 @State private var showingDeleteConfirmation = false
5050 @State private var connectionsUsingProfile = 0
5151
52- private var isEditing : Bool { existingProfile != nil }
52+ private var isStoredProfile : Bool {
53+ guard let profile = existingProfile else { return false }
54+ return SSHProfileStorage . shared. profile ( for: profile. id) != nil
55+ }
5356
5457 private var isValid : Bool {
55- !profileName. trimmingCharacters ( in: . whitespaces) . isEmpty
56- && !host. trimmingCharacters ( in: . whitespaces) . isEmpty
58+ let nameValid = !profileName. trimmingCharacters ( in: . whitespaces) . isEmpty
59+ let hostValid = !host. trimmingCharacters ( in: . whitespaces) . isEmpty
60+ let portValid = port. isEmpty || ( Int ( port) . map { ( 1 ... 65_535 ) . contains ( $0) } ?? false )
61+ let authValid = authMethod == . password || authMethod == . sshAgent
62+ || authMethod == . keyboardInteractive || !privateKeyPath. isEmpty
63+ let jumpValid = jumpHosts. allSatisfy ( \. isValid)
64+ return nameValid && hostValid && portValid && authValid && jumpValid
5765 }
5866
5967 private var resolvedAgentSocketPath : String {
@@ -266,7 +274,7 @@ struct SSHProfileEditorView: View {
266274
267275 private var bottomBar : some View {
268276 HStack {
269- if isEditing {
277+ if isStoredProfile {
270278 Button ( role: . destructive) {
271279 connectionsUsingProfile = ConnectionStorage . shared. loadConnections ( )
272280 . filter { $0. sshProfileId == existingProfile? . id } . count
@@ -294,7 +302,7 @@ struct SSHProfileEditorView: View {
294302 Button ( " Cancel " ) { dismiss ( ) }
295303 . keyboardShortcut ( . cancelAction)
296304
297- Button ( isEditing ? " Save " : " Create " ) { saveProfile ( ) }
305+ Button ( isStoredProfile ? " Save " : " Create " ) { saveProfile ( ) }
298306 . keyboardShortcut ( . defaultAction)
299307 . disabled ( !isValid)
300308 }
@@ -349,7 +357,7 @@ struct SSHProfileEditorView: View {
349357 totpPeriod: totpPeriod
350358 )
351359
352- if isEditing {
360+ if isStoredProfile {
353361 SSHProfileStorage . shared. updateProfile ( profile)
354362 } else {
355363 SSHProfileStorage . shared. addProfile ( profile)
0 commit comments