feat(desktop): multi-window with per-window organization context (#4018)

Merged
AS
3mo ago
+1381-252

Description

Adds VS Code–style multiple windows, each bound to its own organization, to the desktop app. Open a second window (File → New Window), switch it to a different org, and work on two platforms side by side — switching the org in one window never affects another. Each window's title shows its org, and open windows are restored on relaunch.

This implements option 3(b) ("per-window organization context") from #4018 — the smallest slice that delivers the core "work on multiple platforms at once" goal.

How it works: each BrowserWindow is its own renderer with its own active org. tRPC calls resolve the calling window from the IPC sender (ctx.senderWindow), so a window's org is tracked per-window in the main process and used to scope its cloud data (the desktop API client sends x-superset-organization-id; Electric shapes already take organizationId). Previously, switching org mutated the shared login session (authClient.organization.setActive) — inherently global; this PR makes switching window-local.

flowchart LR
  subgraph A["Window A — renderer"]
    CA["CollectionsProvider<br/>activeOrg = Org A"]
  end
  subgraph B["Window B — renderer"]
    CB["CollectionsProvider<br/>activeOrg = Org B"]
  end
  CA -- "getActiveOrg / setActiveOrg<br/>(ctx.senderWindow = 1)" --> REG[("Window registry<br/>windowId to org")]
  CB -- "getActiveOrg / setActiveOrg<br/>(ctx.senderWindow = 2)" --> REG
  CA -- "x-superset-organization-id: Org A" --> CLOUD[("Cloud API + Electric")]
  CB -- "x-superset-organization-id: Org B" --> CLOUD

What's included

  • Multi-window foundation — a window registry (single source of truth for open windows + their org) and a split of MainWindow() into one-time initAppServices() (IPC handler, menu) and a repeatable createPlatformWindow(). App-wide services (notifications HTTP server on a fixed port, terminal/notification listeners) start on the first window and stop on the last, so a second window can't rebind the port or double-register. Adds File → New Window (⇧⌘N on macOS, Ctrl+Alt+N on Windows/Linux), and gives the Window menu the macOS windowMenu role so the open windows are listed and switchable.
  • Per-window org context — tRPC context exposing ctx.senderWindow, window.getActiveOrg / setActiveOrg / openNew, the x-superset-organization-id header on the desktop API client, and window-local org switching. The host data path (LocalHostServiceProvider, useHostTargetUrl, useHostProjects) reads the window's org rather than the shared session, so each window starts its host service and lists projects for the org it's actually showing.
  • Per-window title — "<Org> — Superset", so windows are distinguishable in Mission Control / the window switcher.
  • Restore on relaunch — persists each window's bounds + org (windows-state.json, migrating from the legacy single-window record) and restores them on launch.

Scope note: targets the v2 cloud UI. In v1 the workspace list is machine-local (the local-db projects/worktrees/workspaces tables have no organizationId), so per-window org has nothing to scope there; on v2 the sidebar reads org-scoped Electric collections via CollectionsProvider, which is what this makes per-window.

Related Issues

Related to #4018 (implements option 3(b); does not close the issue, which also proposes the larger "project groups" design).

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Driven manually on the v2 UI via the Chrome DevTools Protocol against a local dev build:

  • New Window opens an independent second window.
  • Switching window B → Org B leaves window A on Org A (per-window isolation; ctx.senderWindow routes correctly per window).
  • Window titles differ ("Ash 2 — Superset" vs "Local Admin's Team — Superset").
  • Quit + relaunch restores both windows on their orgs (planted a 2-window state; both restored).

Automated: unit tests cover the window registry and window-state persistence/validation. bun run typecheck, Biome (bun run lint), and the touched test suites are green.

Screenshots (if applicable)

Two windows of the same app on different orgs (org switcher top-left differs per window); after quit + relaunch both reopen on their saved orgs. Happy to attach the captures — let me know if you'd like them inline.

Additional Notes

Keyboard shortcut. New Window is on ⇧⌘N (macOS / VS Code convention), and Ctrl+Alt+N on Windows/Linux since Ctrl+Shift+N is already New Workspace there. It's a native menu accelerator, so it fires regardless of which pane has focus. ⇧⌘N is still reserved on paper by QUICK_CREATE_WORKSPACE in registry.ts, but that entry has no handler anywhere in the renderer (single reference, no useHotkey), so nothing is lost. Happy to move New Window to a different chord, or clean up the dormant registry entry, if you'd rather Quick Create keep it.

This is a focused slice — happy to adjust scope/shape per your direction on #4018 (e.g. folding per-window org into the larger "project groups" design). "Allow edits from maintainers" is enabled.

Per CONTRIBUTING, this was discussed first via #4018, and is submitted fork → PR following the Clean Code / boy-scout style guidance.

Summary by CodeRabbit

Release Notes

  • New Features

    • Multi-window support: each window keeps its own active organization context.
    • Added a “New Window” option to the File menu.
    • Window titles now reflect the active organization name.
  • Improvements

    • Deep links and notifications now target the focused (or last-used) window.
    • Window positions and settings are restored more reliably, including across multiple windows.
  • Bug Fixes

    • Organization selection and UI checks are now properly scoped per window.