fix(connection-form): bring the New Connection window to the front on the first open - #2019
Open
datlechin wants to merge 1 commit into
Open
fix(connection-form): bring the New Connection window to the front on the first open#2019datlechin wants to merge 1 commit into
datlechin wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
From the Welcome window, Import from URL opens a sheet. Pasting a connection URL and clicking Import opened the New Connection window behind the Welcome window on the first attempt, then in front on later attempts.
Root cause
Apple documents
openWindowordering a window to the front only when it reuses one. FromOpenWindowAction:There is no ordering or key guarantee on the create path. Meanwhile AppKit hands key status from a dismissing sheet back to its
sheetParentasynchronously, as the dismissal animation ends.ImportFromURLSheet.submit()calledopenWindowand thendismiss(), so both were in flight at once. On the first attempt SwiftUI had to build the window from scratch, so it landed after the Welcome window was raised again. On later attempts the window already existed, soopenWindowtook the documented reuse path, which is a cheap order-front that won the race.Nothing corrected for this. Every AppKit-created window in the app pairs creation with an explicit raise (
TabRouterdoes it at 13 call sites,WindowManager.openTab), but the SwiftUIopenWindowscenes had no such step.Two further problems came from the same cause:
nil, so they all shared one window identity. With a New Connection window already open, a repeat import only re-fronted it.ConnectionFormView'sguard coordinator == nilthen blocked re-initialisation, so the staged URL was never consumed and the pasted URL was silently discarded.The fix
Window identity now encodes intent.
ConnectionFormRequestreplacesUUID?as theWindowGroupvalue:.edit(connectionId:)is stable, so re-opening the same connection reuses its window and gets Apple's documented order-front. This also stops two editors opening on one connection..create(draftId:)carries a fresh id per invocation, so every new connection gets its own window. This followsEditorTabPayload, which already uses a per-windowidfor the same reason, and matches the macOS convention that New always makes a new one.The sheets now sequence instead of racing. The button action stages the draft and dismisses; the window opens from
.sheet(onDismiss:). That is the documented hook, and it is what the HIG prescribes: "Let people dismiss a modal view before presenting another one." Applied to all three creation sheets.The window raises itself.
WindowSelfRaisercallsmakeKeyAndOrderFront(nil)once fromviewDidMoveToWindow. This needs no polling and no window-identifier matching, and it also covers the paths that have no sheet to sequence against (duplicating a connection, File > New Connection). It is a separate type rather than a flag onWindowChromeConfigurator, because that type'supdateNSViewruns on every re-render and a raise must never fire on that cadence.Secrets stay out of the window value.
WindowGroup(for:)values areCodableand SwiftUI persists them for state restoration, andParsedConnectionURLholdspasswordandsshPassword. The value carries only identity; the parsed URL travels inConnectionFormDraftStore, an in-memory store keyed by draft id that clears an entry the moment it is read. This replaces thePendingNewConnectionImportandPendingNewConnectionTypesingletons, whose single global slot was what allowed the URL to be dropped.Also removes
WelcomeViewModel.focusConnectionFormWindow(), which scannedNSApp.windowsin the same call stack asopenWindowand so was almost always a no-op, along with the now-unusedAppLaunchCoordinator.isConnectionFormWindow.Rejected on the evidence:
NSApp.activate(ignoringOtherApps:)(soft-deprecated, and the app is already active so activation was never the problem),orderFrontRegardless()(Apple: "You should rarely need to invoke this method", and it defeats the macOS 13.3+ protection against stealing focus from another app), and any fixed delay.Tests
22 tests, all passing. The ones that would have caught these bugs:
testChoosingATypeStagesTheDraftWithoutOpeningTheWindowasserts the window does not open while the sheet is still up. This is the race itself, at the unit level.testEachStagedDraftOpensItsOwnWindowasserts two creations produce different window values. This is the shared-nilidentity bug.testTheStagedURLReachesTheWindowOpenedForItandtwoStagedDraftsDoNotContaminateEachOthercover the silently dropped URL.ConnectionFormRequestTestscovers equality, the accessors, and theCodableround trip theWindowGroupvalue depends on.Window z-order and key status are not asserted. There is no window server in the test host and no precedent for it in this codebase, so that part is manual: on a fresh launch, first try, Import from URL from the Welcome window.
Heads up on the suite as a whole: it runs 9117 passed / 70 failed locally, and those 70 are pre-existing. I confirmed by running the failing suites (
OracleCellFormattingTests,EtcdPrefixRangeEndTests,MCPPairingServiceTests,DatabaseConnectionExternalAccessTests) on the unmodified base commitc790e763in a clean worktree, where exactly the same tests fail. Unrelated to this branch.Not included
No
docs/change. This restores documented behaviour rather than changing what the feature does.Worth a separate discussion: no mature native client (TablePlus, Postico 2, Sequel Ace, DataGrip, Beekeeper, Compass, DBeaver) opens a separate top-level window for this, they keep the flow in one window. That redesign is out of scope here, and it is blocked anyway by the form needing 560pt of height against a fixed, non-resizable 480pt Welcome window.