A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.
C++
feat(home): loading overlay while testing connection on click
DangHuynh32986226fd9b
diff --git a/windows/Gridex/HomePage.cpp b/windows/Gridex/HomePage.cppindex 11078e6..7fb7838 100644--- a/windows/Gridex/HomePage.cpp+++ b/windows/Gridex/HomePage.cpp@@ -506,60 +506,76 @@ namespace winrt::Gridex::implementation{if (!e.ClickedItem()) return;- // ClickedItem returns the ConnectionCard UserControl- // Read Tag to find connection id+ // Read the connection id from the ConnectionCard's Tag.winrt::hstring connId;if (auto fe = e.ClickedItem().try_as<winrt::Microsoft::UI::Xaml::FrameworkElement>()){if (auto tag = fe.Tag())connId = winrt::unbox_value<winrt::hstring>(tag);}-if (connId.empty()) return;- // Find the connection configDBModels::ConnectionConfig selectedConn;bool found = false;for (const auto& conn : allConnections_){if (conn.id == std::wstring(connId))- {- selectedConn = conn;- found = true;- break;- }+ { selectedConn = conn; found = true; break; }}if (!found) return;- // Test connection BEFORE navigating to workspace. If the test- // fails, show error on HomePage so the user doesn't land on a- // blank workspace with an error dialog they have to dismiss.auto frame = this->Frame();if (!frame) return;- try+ // Show the loading overlay so the user gets visual feedback+ // during the connect probe (otherwise the UI looks frozen,+ // especially for SSH tunnels / cold remote DBs).+ ConnectingText().Text(L"Connecting to " + selectedConn.name + L"...");+ ConnectingOverlay().Visibility(mux::Visibility::Visible);++ // Capture a strong ref + dispatcher so the worker thread can+ // bounce back to the UI thread to flip visibility / navigate+ // / show the error dialog. std::thread is detached — fire and+ // forget; the strong ref keeps the page alive long enough.+ auto self = get_strong();+ auto dispatcher = this->DispatcherQueue();+ auto config = selectedConn;+ auto password = selectedConn.password;++ std::thread([self, dispatcher, config, password, frame]() mutable{- DBModels::ConnectionManager mgr;+ bool ok = false;std::wstring err;- if (!mgr.testConnectionWithError(selectedConn, selectedConn.password, err))+ try{- std::wstring msg = L"Could not connect to " + selectedConn.name + L".";- if (!err.empty()) msg += L"\n\n" + err;- else msg += L" Check host, port, credentials, and ensure the server is running.";- muxc::ContentDialog errDlg;- errDlg.Title(winrt::box_value(winrt::hstring(L"Connection Failed")));- errDlg.Content(winrt::box_value(winrt::hstring(msg)));- errDlg.CloseButtonText(L"OK");- errDlg.XamlRoot(this->XamlRoot());- errDlg.ShowAsync();- return;+ DBModels::ConnectionManager mgr;+ ok = mgr.testConnectionWithError(config, password, err);}- }- catch (...) {}+ catch (...) { ok = false; }++ dispatcher.TryEnqueue([self, ok, err, config, password, frame]() mutable+ {+ self->ConnectingOverlay().Visibility(mux::Visibility::Collapsed);++ if (!ok)+ {+ std::wstring msg = L"Could not connect to " + config.name + L".";+ if (!err.empty()) msg += L"\n\n" + err;+ else msg += L" Check host, port, credentials, and ensure the server is running.";+ muxc::ContentDialog errDlg;+ errDlg.Title(winrt::box_value(winrt::hstring(L"Connection Failed")));+ errDlg.Content(winrt::box_value(winrt::hstring(msg)));+ errDlg.CloseButtonText(L"OK");+ errDlg.XamlRoot(self->XamlRoot());+ errDlg.ShowAsync();+ return;+ }- auto workspace = winrt::make<WorkspacePage>();- workspace.as<WorkspacePage>()->SetConnection(selectedConn, selectedConn.password);- frame.Content(workspace);+ auto workspace = winrt::make<WorkspacePage>();+ workspace.as<WorkspacePage>()->SetConnection(config, password);+ frame.Content(workspace);+ });+ }).detach();}void HomePage::SearchBox_TextChanged(diff --git a/windows/Gridex/HomePage.h b/windows/Gridex/HomePage.hindex 286394a..3aa6738 100644--- a/windows/Gridex/HomePage.h+++ b/windows/Gridex/HomePage.h@@ -30,6 +30,10 @@ namespace winrt::Gridex::implementationwinrt::fire_and_forget ImportConnections_Click(winrt::Windows::Foundation::IInspectable const& sender,winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);+ // Spawns a worker thread for the connect probe so the UI+ // thread stays responsive (loading overlay animates), then+ // bounces back via DispatcherQueue::TryEnqueue to navigate+ // or surface the error dialog.void ConnectionItem_Click(winrt::Windows::Foundation::IInspectable const& sender,winrt::Microsoft::UI::Xaml::Controls::ItemClickEventArgs const& e);diff --git a/windows/Gridex/HomePage.xaml b/windows/Gridex/HomePage.xamlindex a5ecc3e..f7faa13 100644--- a/windows/Gridex/HomePage.xaml+++ b/windows/Gridex/HomePage.xaml@@ -198,5 +198,25 @@Click="NewConnection_Click" /></StackPanel></Grid>++ <!-- Modal loading overlay shown while ConnectionItem_Click tests+ the selected connection. Sits on top of every column and+ intercepts clicks via IsHitTestVisible default true. -->+ <Grid x:Name="ConnectingOverlay"+ Grid.Column="0" Grid.ColumnSpan="3"+ Background="#80000000"+ Visibility="Collapsed">+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"+ Spacing="12" Padding="32"+ Background="{ThemeResource SolidBackgroundFillColorBaseBrush}"+ BorderBrush="{ThemeResource ControlStrokeColorDefaultBrush}"+ BorderThickness="1" CornerRadius="8">+ <ProgressRing IsActive="True" Width="40" Height="40" />+ <TextBlock x:Name="ConnectingText"+ Text="Connecting..."+ HorizontalAlignment="Center"+ FontSize="13" />+ </StackPanel>+ </Grid></Grid></Page>