Skip to content

fix: close main window before reopening welcome on connection failure#236

Merged
datlechin merged 1 commit intomainfrom
fix/connection-failure-window-cleanup
Mar 9, 2026
Merged

fix: close main window before reopening welcome on connection failure#236
datlechin merged 1 commit intomainfrom
fix/connection-failure-window-cleanup

Conversation

@datlechin
Copy link
Owner

Summary

  • When a connection fails (e.g., disabled plugin), the main window was left open behind the welcome screen, causing macOS automatic window tabbing to merge them — resulting in a visual flicker and the main window tab appearing inside the welcome window.
  • Now closes the main window before reopening the welcome window, preventing the tab merge. Extracted handleConnectionFailure for clarity.

Test plan

  • Disable a plugin (e.g., MySQL) in Settings > Plugins
  • Double-click a MySQL connection in the welcome screen
  • Verify: error alert appears, main window is gone, welcome screen is clean with no extra tabs

@datlechin datlechin merged commit 6f5ed15 into main Mar 9, 2026
2 checks passed
@datlechin datlechin deleted the fix/connection-failure-window-cleanup branch March 9, 2026 16:02
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1fdb5e9004

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
Self.logger.error(
"Failed to connect: \(error.localizedDescription, privacy: .public)")
handleConnectionFailure(error: error)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Run failure recovery on the MainActor

In connectToDatabase, the catch path now calls handleConnectionFailure directly from an unstructured Task, but that helper performs AppKit/SwiftUI UI work (closeWindows, openWindow, AlertHelper.showErrorSheet). Because the previous await MainActor.run hop was removed, failed connections can execute UI operations off the main actor, which can trigger AppKit thread-safety crashes or undefined UI behavior during connection errors.

Useful? React with 👍 / 👎.


private func handleConnectionFailure(error: Error) {
// Close the main window first so macOS doesn't merge it with the welcome window
NSApplication.shared.closeWindows(withId: "main")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Close only the failed main window

handleConnectionFailure now calls NSApplication.shared.closeWindows(withId: "main"), and that helper closes all windows whose identifier contains main. In sessions where users already have other main windows open (for example after opening Welcome via “Manage Connections”), one failed connection attempt will close unrelated active windows/tabs and can drop in-progress work.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant