@@ -32,6 +32,22 @@ struct ConnectionFormView: View {
3232 PluginManager . shared. additionalConnectionFields ( for: type)
3333 }
3434
35+ private var authSectionFields : [ ConnectionField ] {
36+ PluginManager . shared. additionalConnectionFields ( for: type)
37+ . filter { $0. section == . authentication }
38+ }
39+
40+ private var hidePasswordField : Bool {
41+ authSectionFields. contains { $0. hidesPassword && additionalFieldValues [ $0. id] == " true " }
42+ }
43+
44+ private func toggleBinding( for fieldId: String ) -> Binding < Bool > {
45+ Binding (
46+ get: { additionalFieldValues [ fieldId] == " true " } ,
47+ set: { additionalFieldValues [ fieldId] = $0 ? " true " : " false " }
48+ )
49+ }
50+
3551 @State private var name : String = " "
3652 @State private var host : String = " "
3753 @State private var port : String = " "
@@ -83,9 +99,19 @@ struct ConnectionFormView: View {
8399 @State private var startupCommands : String = " "
84100
85101 // Pgpass
86- @State private var usePgpass : Bool = false
87102 @State private var pgpassStatus : PgpassStatus = . notChecked
88103
104+ private var usePgpass : Bool {
105+ additionalFieldValues [ " usePgpass " ] == " true "
106+ }
107+
108+ private var usePgpassBinding : Binding < Bool > {
109+ Binding (
110+ get: { additionalFieldValues [ " usePgpass " ] == " true " } ,
111+ set: { additionalFieldValues [ " usePgpass " ] = $0 ? " true " : " false " }
112+ )
113+ }
114+
89115 // Pre-connect script
90116 @State private var preConnectScript : String = " "
91117
@@ -148,9 +174,6 @@ struct ConnectionFormView: View {
148174 selectedTab = . general
149175 }
150176 additionalFieldValues = [ : ]
151- if newType. pluginTypeId != " PostgreSQL " {
152- usePgpass = false
153- }
154177 for field in PluginManager . shared. additionalConnectionFields ( for: newType) {
155178 if let defaultValue = field. defaultValue {
156179 additionalFieldValues [ field. id] = defaultValue
@@ -160,7 +183,7 @@ struct ConnectionFormView: View {
160183 . pluginInstallPrompt ( connection: $pluginInstallConnection) { connection in
161184 connectAfterInstall ( connection)
162185 }
163- . onChange ( of: usePgpass ) { _, _ in updatePgpassStatus ( ) }
186+ . onChange ( of: additionalFieldValues ) { _, _ in updatePgpassStatus ( ) }
164187 . onChange ( of: host) { _, _ in updatePgpassStatus ( ) }
165188 . onChange ( of: port) { _, _ in updatePgpassStatus ( ) }
166189 . onChange ( of: database) { _, _ in updatePgpassStatus ( ) }
@@ -170,10 +193,15 @@ struct ConnectionFormView: View {
170193 // MARK: - Tab Picker Helpers
171194
172195 private var visibleTabs : [ FormTab ] {
173- if PluginManager . shared. connectionMode ( for: type) == . fileBased {
174- return [ . general, . advanced]
196+ var tabs : [ FormTab ] = [ . general]
197+ if PluginManager . shared. supportsSSH ( for: type) {
198+ tabs. append ( . ssh)
199+ }
200+ if PluginManager . shared. supportsSSL ( for: type) {
201+ tabs. append ( . ssl)
175202 }
176- return FormTab . allCases
203+ tabs. append ( . advanced)
204+ return tabs
177205 }
178206
179207 private var resolvedSSHAgentSocketPath : String {
@@ -273,16 +301,18 @@ struct ConnectionFormView: View {
273301 prompt: Text ( " root " )
274302 )
275303 }
276- if type. pluginTypeId == " PostgreSQL " {
277- Toggle ( String ( localized: " Use ~/.pgpass " ) , isOn: $usePgpass)
304+ ForEach ( authSectionFields, id: \. id) { field in
305+ if field. fieldType == . toggle {
306+ Toggle ( field. label, isOn: toggleBinding ( for: field. id) )
307+ }
278308 }
279- if !usePgpass || type . pluginTypeId != " PostgreSQL " {
309+ if !hidePasswordField {
280310 SecureField (
281311 String ( localized: " Password " ) ,
282312 text: $password
283313 )
284314 }
285- if usePgpass && type . pluginTypeId == " PostgreSQL " {
315+ if additionalFieldValues [ " usePgpass " ] == " true " {
286316 pgpassStatusView
287317 }
288318 }
@@ -775,7 +805,7 @@ struct ConnectionFormView: View {
775805 }
776806
777807 private func updatePgpassStatus( ) {
778- guard usePgpass, type . pluginTypeId == " PostgreSQL " else {
808+ guard additionalFieldValues [ " usePgpass " ] == " true " else {
779809 pgpassStatus = . notChecked
780810 return
781811 }
@@ -827,8 +857,8 @@ struct ConnectionFormView: View {
827857 additionalFieldValues = existing. additionalFields
828858
829859 // Migrate legacy Redis database index before default seeding
830- if existing . type . pluginTypeId == " Redis " ,
831- additionalFieldValues [ " redisDatabase " ] == nil ,
860+ // Migrate legacy redisDatabase to additionalFields
861+ if additionalFieldValues [ " redisDatabase " ] == nil ,
832862 let rdb = existing. redisDatabase {
833863 additionalFieldValues [ " redisDatabase " ] = String ( rdb)
834864 }
@@ -841,7 +871,6 @@ struct ConnectionFormView: View {
841871
842872 // Load startup commands
843873 startupCommands = existing. startupCommands ?? " "
844- usePgpass = existing. usePgpass
845874 preConnectScript = existing. preConnectScript ?? " "
846875
847876 // Load passwords from Keychain
@@ -888,11 +917,6 @@ struct ConnectionFormView: View {
888917 ? " root " : trimmedUsername
889918
890919 var finalAdditionalFields = additionalFieldValues
891- if usePgpass && type. pluginTypeId == " PostgreSQL " {
892- finalAdditionalFields [ " usePgpass " ] = " true "
893- } else {
894- finalAdditionalFields. removeValue ( forKey: " usePgpass " )
895- }
896920 let trimmedScript = preConnectScript. trimmingCharacters ( in: . whitespacesAndNewlines)
897921 if !trimmedScript. isEmpty {
898922 finalAdditionalFields [ " preConnectScript " ] = preConnectScript
@@ -915,9 +939,7 @@ struct ConnectionFormView: View {
915939 groupId: selectedGroupId,
916940 safeModeLevel: safeModeLevel,
917941 aiPolicy: aiPolicy,
918- redisDatabase: type. pluginTypeId == " Redis "
919- ? Int ( additionalFieldValues [ " redisDatabase " ] ?? " 0 " )
920- : nil ,
942+ redisDatabase: Int ( additionalFieldValues [ " redisDatabase " ] ?? " " ) ,
921943 startupCommands: startupCommands. trimmingCharacters ( in: . whitespacesAndNewlines) . isEmpty
922944 ? nil : startupCommands,
923945 additionalFields: finalAdditionalFields. isEmpty ? nil : finalAdditionalFields
@@ -1047,11 +1069,6 @@ struct ConnectionFormView: View {
10471069 ? " root " : trimmedUsername
10481070
10491071 var finalAdditionalFields = additionalFieldValues
1050- if usePgpass && type. pluginTypeId == " PostgreSQL " {
1051- finalAdditionalFields [ " usePgpass " ] = " true "
1052- } else {
1053- finalAdditionalFields. removeValue ( forKey: " usePgpass " )
1054- }
10551072 let trimmedScript = preConnectScript. trimmingCharacters ( in: . whitespacesAndNewlines)
10561073 if !trimmedScript. isEmpty {
10571074 finalAdditionalFields [ " preConnectScript " ] = preConnectScript
@@ -1071,9 +1088,7 @@ struct ConnectionFormView: View {
10711088 color: connectionColor,
10721089 tagId: selectedTagId,
10731090 groupId: selectedGroupId,
1074- redisDatabase: type. pluginTypeId == " Redis "
1075- ? Int ( additionalFieldValues [ " redisDatabase " ] ?? " 0 " )
1076- : nil ,
1091+ redisDatabase: Int ( additionalFieldValues [ " redisDatabase " ] ?? " " ) ,
10771092 startupCommands: startupCommands. trimmingCharacters ( in: . whitespacesAndNewlines) . isEmpty
10781093 ? nil : startupCommands,
10791094 additionalFields: finalAdditionalFields. isEmpty ? nil : finalAdditionalFields
0 commit comments