@@ -85,11 +85,11 @@ struct ConnectionFormView: View {
8585 @State private var startupCommands : String = " "
8686
8787 @State private var isTesting : Bool = false
88- @State private var testResult : TestResult ?
88+ @State private var testSucceeded : Bool = false
8989
9090 @State private var isInstallingPlugin = false
9191 @State private var pluginInstallProgress : Double = 0
92- @ State private var showPluginInstallError : String ?
92+
9393 @State private var pluginInstallConnection : DatabaseConnection ?
9494
9595 // Tab selection
@@ -100,11 +100,6 @@ struct ConnectionFormView: View {
100100
101101 // MARK: - Enums
102102
103- enum TestResult {
104- case success
105- case failure( String )
106- }
107-
108103 private enum FormTab : String , CaseIterable {
109104 case general = " General "
110105 case ssh = " SSH Tunnel "
@@ -139,7 +134,6 @@ struct ConnectionFormView: View {
139134 isNew ? String ( localized: " New Connection " ) : String ( localized: " Edit Connection " )
140135 )
141136 . onAppear {
142- PluginManager . shared. loadPendingPlugins ( )
143137 loadConnectionData ( )
144138 loadSSHConfig ( )
145139 }
@@ -680,32 +674,6 @@ struct ConnectionFormView: View {
680674 . padding ( . top, 8 )
681675 }
682676
683- if case . failure( let message) = testResult {
684- HStack ( alignment: . top, spacing: 6 ) {
685- Image ( systemName: " exclamationmark.triangle.fill " )
686- . foregroundStyle ( . red)
687- Text ( message)
688- . font ( . caption)
689- . foregroundStyle ( . red)
690- . fixedSize ( horizontal: false , vertical: true )
691- }
692- . padding ( . horizontal, 16 )
693- . padding ( . top, 8 )
694- }
695-
696- if let pluginError = showPluginInstallError {
697- HStack ( alignment: . top, spacing: 6 ) {
698- Image ( systemName: " exclamationmark.triangle.fill " )
699- . foregroundStyle ( . red)
700- Text ( pluginError)
701- . font ( . caption)
702- . foregroundStyle ( . red)
703- . fixedSize ( horizontal: false , vertical: true )
704- }
705- . padding ( . horizontal, 16 )
706- . padding ( . top, 8 )
707- }
708-
709677 HStack {
710678 // Test connection
711679 Button ( action: testConnection) {
@@ -714,8 +682,8 @@ struct ConnectionFormView: View {
714682 ProgressView ( )
715683 . controlSize ( . small)
716684 } else {
717- Image ( systemName: testResultIcon )
718- . foregroundStyle ( testResultColor )
685+ Image ( systemName: testSucceeded ? " checkmark.circle.fill " : " bolt.horizontal " )
686+ . foregroundStyle ( testSucceeded ? . green : . secondary )
719687 }
720688 Text ( " Test Connection " )
721689 }
@@ -783,26 +751,10 @@ struct ConnectionFormView: View {
783751 return basicValid
784752 }
785753
786- private var testResultIcon : String {
787- switch testResult {
788- case . success: return " checkmark.circle.fill "
789- case . failure: return " xmark.circle.fill "
790- case . none: return " bolt.horizontal "
791- }
792- }
793-
794- private var testResultColor : Color {
795- switch testResult {
796- case . success: return . green
797- case . failure: return . red
798- case . none: return . secondary
799- }
800- }
801-
802754 private func installPluginForType( _ databaseType: DatabaseType ) {
803755 isInstallingPlugin = true
804756 pluginInstallProgress = 0
805- showPluginInstallError = nil
757+ let window = NSApp . keyWindow
806758
807759 Task {
808760 do {
@@ -812,7 +764,11 @@ struct ConnectionFormView: View {
812764 isInstallingPlugin = false
813765 } catch {
814766 isInstallingPlugin = false
815- showPluginInstallError = error. localizedDescription
767+ AlertHelper . showErrorSheet (
768+ title: String ( localized: " Plugin Installation Failed " ) ,
769+ message: error. localizedDescription,
770+ window: window
771+ )
816772 }
817773 }
818774 }
@@ -1012,7 +968,8 @@ struct ConnectionFormView: View {
1012968
1013969 func testConnection( ) {
1014970 isTesting = true
1015- testResult = nil
971+ testSucceeded = false
972+ let window = NSApp . keyWindow
1016973
1017974 // Build SSH config
1018975 let sshConfig = SSHConfiguration (
@@ -1080,13 +1037,24 @@ struct ConnectionFormView: View {
10801037 testConn, sshPassword: sshPassword)
10811038 await MainActor . run {
10821039 isTesting = false
1083- testResult =
1084- success ? . success : . failure( String ( localized: " Connection test failed " ) )
1040+ if success {
1041+ testSucceeded = true
1042+ } else {
1043+ AlertHelper . showErrorSheet (
1044+ title: String ( localized: " Connection Test Failed " ) ,
1045+ message: String ( localized: " Connection test failed " ) ,
1046+ window: window
1047+ )
1048+ }
10851049 }
10861050 } catch {
10871051 await MainActor . run {
10881052 isTesting = false
1089- testResult = . failure( error. localizedDescription)
1053+ AlertHelper . showErrorSheet (
1054+ title: String ( localized: " Connection Test Failed " ) ,
1055+ message: error. localizedDescription,
1056+ window: window
1057+ )
10901058 }
10911059 }
10921060 }
0 commit comments