Skip to content

feat: detect when multiple windows open the same workspace#918

Merged
EhabY merged 4 commits intomainfrom
feat/multi-window-ipc
Apr 28, 2026
Merged

feat: detect when multiple windows open the same workspace#918
EhabY merged 4 commits intomainfrom
feat/multi-window-ipc

Conversation

@EhabY
Copy link
Copy Markdown
Collaborator

@EhabY EhabY commented Apr 27, 2026

Summary

Adds WindowBroadcast<T>, a generic typed pub/sub channel built on top of SecretStorage.onDidChange, and uses it to detect when more than one VS Code window is connected to the same Coder workspace.

Closes #783, #548

How it works

When a user clicks Connect, the extension fires openFolder() immediately and sends a PING through SecretStorage in parallel. If another window responds with a PONG, the clicking window shows a non-blocking notification with two choices:

  • Duplicate Window: tells the responding window to run duplicateWorkspaceInNewWindow, preserving its tabs, panels, and remote connection.
  • Open Without Folder: opens a new window connected to the remote with no folder.

The whole chain is fire-and-forget. openWorkspace() never blocks on it, so if no other window is listening the behavior is identical to before.

Layout

File Role
src/ipc/windowBroadcast.ts Generic typed pub/sub primitive over a single SecretStorage key
src/workspace/duplicateWorkspaceIpc.ts PING / PONG / DUPLICATE protocol used by the open-workspace flow
src/oauth/oauthCallback.ts Cross-window OAuth redirect signal, also built on WindowBroadcast
src/commands.ts Sends PING in parallel with openFolder() and shows the notification
src/extension.ts Responds to PINGs and runs duplicateWorkspaceInNewWindow when targeted

Each consumer of WindowBroadcast defines its message shape with a Zod schema, so invalid or stale data on the storage key is dropped before reaching handlers.

Notes

  • WindowBroadcast is the only generic piece. Specializations live with their feature (OAuth signal in oauth/, workspace duplicate detection in workspace/) rather than in a shared IPC bucket.
  • The notification uses non-modal showInformationMessage, which VS Code may dismiss without resolving, so the chain must not be awaited from the open path.
  • The notification is shown in the window where the user clicked, so it always appears in a predictable place regardless of which window VS Code routes focus to.

@EhabY EhabY self-assigned this Apr 27, 2026
@EhabY EhabY force-pushed the feat/multi-window-ipc branch 4 times, most recently from 2d482fc to 95ba149 Compare April 27, 2026 16:41
@EhabY EhabY changed the title feat: support multiple VS Code windows to the same workspace feat: detect when multiple windows open the same workspace Apr 28, 2026
@EhabY EhabY force-pushed the feat/multi-window-ipc branch from 53448a5 to b07d0c6 Compare April 28, 2026 10:32
Comment thread src/ipc/windowBroadcast.ts
Comment thread src/ipc/windowBroadcast.ts
Comment thread src/workspace/duplicateWorkspaceIpc.ts
Comment thread src/workspace/duplicateWorkspaceIpc.ts
Comment thread src/workspace/duplicateWorkspaceIpc.ts Outdated
Comment thread src/workspace/duplicateWorkspaceIpc.ts
EhabY and others added 3 commits April 28, 2026 14:49
Add WindowBroadcast<T>, a generic typed pub/sub channel over
SecretStorage.onDidChange for transient cross-window messaging.

Build WindowIpc on top of two broadcast channels to detect when
multiple windows are connected to the same Coder workspace. When a
user clicks Connect and another window responds to the PING, a
non-blocking notification offers Duplicate Window or Open Without
Folder. The entire chain is fire-and-forget; openWorkspace() never
blocks on it.

Closes #783
Closes #548
Address review feedback:
- Move OAuthCallback out of SecretsManager into src/oauth/oauthCallback.ts
- Move WindowBroadcast (the generic primitive) into src/ipc/
- Rename WindowIpc to DuplicateWorkspaceIpc and move it into src/workspace/, since it covers a single workspace-coordination feature, not all window IPC
- Use Zod schemas in both DuplicateWorkspaceIpc and OAuthCallback for consistent validation
- Tighten tests: the broadcast key-isolation test now also asserts delivery on the matching key, and the stale-request test asserts delivery of fresh requests
@EhabY EhabY force-pushed the feat/multi-window-ipc branch from b07d0c6 to c0807b4 Compare April 28, 2026 12:04
@EhabY EhabY requested a review from mtojek April 28, 2026 12:05
@EhabY EhabY force-pushed the feat/multi-window-ipc branch from c0807b4 to 2f53028 Compare April 28, 2026 12:08
Comment thread src/workspace/duplicateWorkspaceIpc.ts
@EhabY EhabY merged commit b7bc503 into main Apr 28, 2026
6 checks passed
@EhabY EhabY deleted the feat/multi-window-ipc branch April 28, 2026 12:43
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.

Option to open workspace in new window

2 participants