Skip to content

Commit 25ca799

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
feat(desktop): New Window and deep links follow one dispatch table
## What Changed Every window request resolves through one table in `apps/desktop/src/window/WindowDispatch.fork.ts`. The startup drain and the second-instance buffer use the same table. | Request | Behavior | | --- | --- | | New Window (menu, palette, key) | create at `/`, all projects | | Open in New Window (row, thread) | create at that route, seed filter | | Second launch, dock | focus most recent, else create | | Deep link, `--project` | reuse a window showing it, else create | | Focus window by id | focus if open; never resurrect | | OAuth callback | unchanged | - **Surfaces:** File > New Window, palette action, thread menu item - **Bindings:** `window.new` on `mod+shift+w` - **Rename:** `project.openWindow` becomes `window.openInNew` - **Migration:** saved bindings with the old id load unchanged - **IPC:** `openProjectWindow` replaced by `requestWindow` - **Seed:** New Window seeds `"all-projects"`; Open in New Window and deep links seed their project - **Recency:** a second launch focuses the first of `windowsByRecency` - **Scope guard:** kept; a project window that leaves its project still closes, and closes itself rather than the first window sharing its project - **List routes:** Issues and Pull requests keep a project window in its project from a shared page - **Other project's item:** an issue or pull request link from another project widens the list to all projects, reading the window's project when the pathname names none - **Guard close:** skipped when the window is already destroyed by the time the hub is revealed - **Queued second launch:** drained after boot, it only creates main when none exists and never reveals a window ## Why Closes #1343 Closes #1344 Window requests had separate paths with different reuse rules. One table makes each row testable and keys windows by `WindowId` only. ### Issue work route Issue work from `/project/<env>/<project>/issues` drafts at `/project/<env>/<project>/draft/<id>`, which the guard allows. The route that bounced was the hub `/issues`. Issues, from a shared page such as `/settings` in a project window, read the project from the pathname, found none, and navigated to `/issues`. The guard then revealed the hub and closed the window. `listRouteTarget` now falls back to the window's own project, so Issues and Pull requests stay on the project routes. #179 left the route unconfirmed, and no desktop log still holds a `project window left its scope` line. The trace came from the source; live proof then confirmed the fixed route (steps 70–74 below). ### Known limits Refs #1345 - **Update relaunch:** extra hub or same-project windows are dropped; `DesktopWindowSession` dedups by identity and the startup drain restores through `getOrCreate` - **New Window as hub:** when main closes, a New Window becomes main, but its bounds are never saved ## Close conditions - [x] Table: each row has a focused test - `WindowDispatch.fork.test.ts`: one test per row, plus argv classification - [x] Binding: `mod+shift+w`, conflict-checked - `keybindings.fork.test.ts`: no other default owns the chord - [x] `mod+alt+o`: renamed; now always opens a new window, per the table - live: a second press creates a second window where `openIdentity` reused one (step 41) - migration of existing `keybindings.json`: unit-tested, not live - [x] Issue work: thread opens in the source window - live: steps 70–74; issues from settings stay in the project, the draft opens there, and the guard closes only itself - `DesktopWindow.fork.test.ts`: issue work stays in its window; another project is still guarded - `projectRoutes.test.ts`: lists from a shared page stay in the window's project - [x] Seed (#1344): New Window opens on all projects; Open in New Window opens on its project - live: New Window by key, menu, and palette (steps 20–22); Open in New Window by row and thread menu (steps 30–31) - `DesktopWindow.fork.test.ts`: the seed preload argument per request - [x] Deep link: reuses a window showing the project, else creates one - live: steps 50–51 - [x] Second launch: focuses the most recent window - live: steps 63 and 65; Linux has no dock activate Live proof ran at `025eb14c81` on a client-only dev Electron over a seeded copy, 6/6 pass, no stray windows. Evidence: `.dump/evidence/1369-live/` on the host, indexed by `transcript.json`; step N is its `N-*` files. ## Checks ```text vp test run (desktop window/ipc/app/electron) → exit 0, 60 files, 409 tests vp test run (web links, routes, sidebar) → exit 0, 17 files, 539 tests vpr typecheck → exit 0 vp run knip:check → exit 0 vp run fork:ci → exit 0 ``` Swap proofs, each reverted: ```diff - open-in-new-window reuses a showing window → 1 test fails - activate goes to openPrimary → 1 test fails - migration returns input unchanged → 2 tests fail - New Window default mod+shift+n → 2 tests fail - dispatched window counted as primary → 1 test fails - guard never closes → 2 tests fail - guard allows only the exact project route → 1 test fails - list route ignores the window's project → 1 test fails - seed not passed to the preload → 1 test fails - most recent read from the oldest window → 1 test fails - guard closes a destroyed window → 1 test fails - drained second launch takes the table row → 1 test fails - link scope ignores the window's project → 1 test fails ``` ## UI Changes New menu, palette, and thread-menu items. Screenshots stay in the host evidence directory above; they show private thread titles. ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [ ] I included before/after screenshots for any UI changes - [ ] I included a video for animation/interaction changes Model: Claude Opus 5.5, Claude Code in T3 Code. ## Fork trailers Squashes: - 9d6e5df feat(desktop): New Window and deep links follow one dispatch table - fd56cc1 fix(desktop): mod+alt+o reuses the project's window again - 7d18eaf feat(desktop): New Window and deep links follow one dispatch table - faa53bd refactor(multi-window): createWindow seams become marked insertions (#1811) (#1811) Fork-Domain: multi-window Fork-Tier: core
1 parent e95355d commit 25ca799

50 files changed

Lines changed: 1311 additions & 215 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/app/DesktopLifecycle.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function layerElectronWindow(destroyAll: Effect.Effect<void> = Effect.void) {
7070
get: () => Effect.die("unexpected identity window read"),
7171
getById: () => Effect.die("unexpected window id read"), // fork-hook: multi-window/window-id-get-by-id
7272
getOrCreate: () => Effect.die("unexpected identity window creation"),
73+
createNew: () => Effect.die("unexpected new window creation"), // fork-hook: multi-window/dispatch-create-new
7374
close: () => Effect.void,
7475
windowIdFor: () => Effect.succeed(Option.none()), // fork-hook: multi-window/window-id-for
7576
listWindows: Effect.succeed([]), // fork-hook: multi-window/window-id-list
@@ -96,7 +97,7 @@ function layerDesktopWindow(
9697
createMain: Effect.die("unexpected window creation"),
9798
ensureMain: Effect.die("unexpected window creation"),
9899
revealOrCreateMain: Effect.die("unexpected window creation"),
99-
openIdentity: () => Effect.die("unexpected identity window open"),
100+
requestWindow: () => Effect.die("unexpected window request"), // fork-hook: multi-window/dispatch-request
100101
openArguments: () => Effect.void,
101102
restoreWindowSession: Effect.void,
102103
closeIdentity: () => Effect.void,

‎apps/desktop/src/app/DesktopSecondInstanceBuffer.fork.test.ts‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import {
1010
type StartupDrainServices,
1111
type WindowOpeners,
1212
} from "../window/DesktopStartupDrain.fork.ts";
13-
import { projectWindowIdentity, type WindowIdentity } from "../window/WindowIdentity.ts";
13+
import type { WindowRequest } from "../window/WindowDispatch.fork.ts";
1414
import { makeSecondInstanceBuffer } from "./DesktopSecondInstanceBuffer.fork.ts";
1515

16-
const fakeWindow = {} as Electron.BrowserWindow;
17-
1816
const noopServices: StartupDrainServices = {
1917
hyprlandPlacement: {
2018
isAvailable: false,
@@ -42,14 +40,17 @@ const makeFakeApp = () => {
4240
return { electronApp, emit } as const;
4341
};
4442

45-
// argv is ["t3code", <name>]; the resolver maps the name to a project window.
46-
const identityOf = (argv: readonly string[]): WindowIdentity | null =>
43+
// argv is ["t3code", <name>]; the resolver maps the name to a project deep link.
44+
const requestOf = (argv: readonly string[]): WindowRequest =>
4745
argv[1] === undefined
48-
? null
49-
: projectWindowIdentity(
50-
EnvironmentId.make(`environment-${argv[1]}`),
51-
ProjectId.make(`project-${argv[1]}`),
52-
);
46+
? { kind: "activate" }
47+
: {
48+
kind: "project-link",
49+
ref: {
50+
environmentId: EnvironmentId.make(`environment-${argv[1]}`),
51+
projectId: ProjectId.make(`project-${argv[1]}`),
52+
},
53+
};
5354

5455
describe("DesktopSecondInstanceBuffer", () => {
5556
it.effect("opens a launch emitted before configure after the first intent, once", () =>
@@ -58,18 +59,18 @@ describe("DesktopSecondInstanceBuffer", () => {
5859
const buffer = makeSecondInstanceBuffer();
5960
const app = makeFakeApp();
6061
const opened = yield* Ref.make<ReadonlyArray<string>>([]);
61-
const record = (identity: WindowIdentity) =>
62+
const record = (request: WindowRequest) =>
6263
Ref.update(opened, (keys) => [
6364
...keys,
64-
identity.kind === "hub" ? "hub" : identity.ref.projectId,
65-
]).pipe(Effect.as(fakeWindow));
65+
request.kind === "project-link" ? request.ref.projectId : request.kind,
66+
]);
6667
const openers: WindowOpeners = {
6768
ensureIdentity: () => () => Effect.die("no restore is staged"),
68-
revealOrCreateIdentity: () => record,
69+
dispatch: () => record,
6970
createMainIfBackendReady: () => Effect.void,
7071
};
7172
const stage = (argv: readonly string[]) =>
72-
drain.stageArguments(noopServices, identityOf, argv).pipe(Effect.asVoid);
73+
drain.stageArguments(noopServices, requestOf, argv).pipe(Effect.asVoid);
7374

7475
yield* buffer.listen(app.electronApp);
7576
// Emitted in the gap before configure registers the real listener.

‎apps/desktop/src/backend/DesktopBackendPool.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function layerPool(labelRef: Ref.Ref<string>): Layer.Layer<DesktopBackendPool.De
7171
createMain: Effect.die("unexpected window create"),
7272
ensureMain: Effect.die("unexpected window ensure"),
7373
revealOrCreateMain: Effect.die("unexpected window reveal"),
74-
openIdentity: () => Effect.die("unexpected identity window open"),
74+
requestWindow: () => Effect.die("unexpected window request"), // fork-hook: multi-window/dispatch-request
7575
openArguments: () => Effect.void,
7676
restoreWindowSession: Effect.void,
7777
closeIdentity: () => Effect.void,

‎apps/desktop/src/electron/ElectronWindow.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export class ElectronWindow extends Context.Service<
120120
readonly get: WindowRegistry.WindowRegistryService["get"]; // fork-hook: multi-window/window-registry-get
121121
readonly getById: WindowRegistry.WindowRegistryService["getById"]; // fork-hook: multi-window/window-id-get-by-id
122122
readonly getOrCreate: WindowRegistry.WindowRegistryService["getOrCreate"]; // fork-hook: multi-window/window-id-get-or-create
123+
readonly createNew: WindowRegistry.WindowRegistryService["createNew"]; // fork-hook: multi-window/dispatch-create-new
123124
readonly close: (identity: WindowIdentity) => Effect.Effect<void>;
124125
readonly windowIdFor: WindowRegistry.WindowRegistryService["windowIdFor"]; // fork-hook: multi-window/window-id-for
125126
readonly listWindows: WindowRegistry.WindowRegistryService["listWindows"]; // fork-hook: multi-window/window-id-list

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import {
5151
openSystemSettings,
5252
checkSystemPermission,
5353
pasteAsText,
54-
openProjectWindow,
5554
probeRemoteEditors,
5655
revealWindow,
5756
pickFolder,
@@ -60,6 +59,7 @@ import {
6059
setTheme,
6160
showContextMenu,
6261
} from "./methods/window.ts";
62+
import { requestWindow } from "./methods/window.fork.ts"; // fork-hook: multi-window/dispatch-request-ipc
6363
import {
6464
acknowledgeSnapShot,
6565
checkSnapShotShortcut,
@@ -165,7 +165,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
165165
yield* ipc.handle(checkSystemPermission);
166166
yield* ipc.handle(pasteAsText);
167167
yield* ipc.handle(revealWindow);
168-
yield* ipc.handle(openProjectWindow);
168+
yield* ipc.handle(requestWindow); // fork-hook: multi-window/dispatch-request-ipc
169169
yield* ipc.handle(probeRemoteEditors);
170170
yield* ipc.handle(getUpdateState);
171171
yield* ipc.handle(setUpdateChannel);

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const SET_THEME_CHANNEL = "desktop:set-theme";
66
export const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
77
export const OPEN_EXTERNAL_CHANNEL = "desktop:open-external";
88
export const OPEN_SYSTEM_SETTINGS_CHANNEL = "desktop:open-system-settings";
9-
export const OPEN_PROJECT_WINDOW_CHANNEL = "desktop:open-project-window";
9+
export const REQUEST_WINDOW_CHANNEL = "desktop:request-window"; // fork-hook: multi-window/dispatch-request-ipc
1010
export const PROBE_REMOTE_EDITORS_CHANNEL = "desktop:probe-remote-editors";
1111
export const MENU_ACTION_CHANNEL = "desktop:menu-action";
1212
export const PASTE_AS_TEXT_CHANNEL = "desktop:paste-as-text";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { DesktopWindowRequest } from "@t3tools/contracts";
2+
import * as Effect from "effect/Effect";
3+
import * as Schema from "effect/Schema";
4+
5+
import * as DesktopWindow from "../../window/DesktopWindow.ts";
6+
import * as IpcChannels from "../channels.ts";
7+
import * as DesktopIpc from "../DesktopIpc.ts";
8+
9+
/** Every client window request goes through the one window dispatch table. */
10+
export const requestWindow = DesktopIpc.makeIpcMethod({
11+
channel: IpcChannels.REQUEST_WINDOW_CHANNEL,
12+
payload: DesktopWindowRequest,
13+
result: Schema.Void,
14+
handler: Effect.fn("desktop.ipc.window.requestWindow")(function* (request) {
15+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
16+
yield* desktopWindow.requestWindow(request);
17+
}),
18+
});

‎apps/desktop/src/ipc/methods/window.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
PickFolderOptionsSchema,
1010
PRIMARY_LOCAL_ENVIRONMENT_ID,
1111
REMOTE_CAPABLE_EDITOR_IDS,
12-
ScopedProjectRef,
1312
SystemSettingsPaneSchema,
1413
type DesktopEnvironmentBootstrap,
1514
type PickedThemeFile,
@@ -328,16 +327,6 @@ export const openSystemSettings = DesktopIpc.makeIpcMethod({
328327
}),
329328
});
330329

331-
export const openProjectWindow = DesktopIpc.makeIpcMethod({
332-
channel: IpcChannels.OPEN_PROJECT_WINDOW_CHANNEL,
333-
payload: ScopedProjectRef,
334-
result: Schema.Void,
335-
handler: Effect.fn("desktop.ipc.window.openProjectWindow")(function* (projectRef) {
336-
const desktopWindow = yield* DesktopWindow.DesktopWindow;
337-
yield* desktopWindow.openIdentity({ kind: "project", ref: projectRef });
338-
}),
339-
});
340-
341330
export const probeRemoteEditors = DesktopIpc.makeIpcMethod({
342331
channel: IpcChannels.PROBE_REMOTE_EDITORS_CHANNEL,
343332
payload: Schema.Undefined,

‎apps/desktop/src/preview/WindowPolicy.preload.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type PreviewCapableDesktopBridge = DesktopBridge & {
2020
export type ProjectWindowCapabilities = Required<
2121
Pick<
2222
DesktopBridge,
23-
"openProjectWindow" | "projectWindowRef" | "getWindowDemandState" | "onWindowDemandStateChange"
23+
"requestWindow" | "projectWindowRef" | "getWindowDemandState" | "onWindowDemandStateChange"
2424
>
2525
> &
2626
Pick<DesktopBridge, "windowId" | "windowScopeSeed">;
@@ -45,8 +45,7 @@ ipcRenderer.on(IpcChannels.WINDOW_DEMAND_STATE_CHANNEL, (_event, demanded: unkno
4545
});
4646

4747
const projectWindowCapabilities = (): ProjectWindowCapabilities => ({
48-
openProjectWindow: (projectRef) =>
49-
ipcRenderer.invoke(IpcChannels.OPEN_PROJECT_WINDOW_CHANNEL, projectRef),
48+
requestWindow: (request) => ipcRenderer.invoke(IpcChannels.REQUEST_WINDOW_CHANNEL, request),
5049
// Branded ids are plain strings at runtime; the preload cannot import the
5150
// contracts package without breaking its sandboxed bundle.
5251
projectWindowRef: readProjectWindowPreloadParts(process.argv) as ScopedProjectRef | null,

‎apps/desktop/src/ssh/DesktopSshPasswordPrompts.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function layerElectronWindow(window: ReturnType<typeof makeTestWindow>["window"]
9494
get: () => Effect.succeedSome(window as Electron.BrowserWindow), // fork-hook: project-windows/ssh-prompts-window-get
9595
getById: () => Effect.succeedSome(window as Electron.BrowserWindow), // fork-hook: multi-window/window-id-get-by-id
9696
getOrCreate: () => Effect.die("unexpected identity window creation"),
97+
createNew: () => Effect.die("unexpected new window creation"), // fork-hook: multi-window/dispatch-create-new
9798
close: () => Effect.void,
9899
windowIdFor: () => Effect.succeedNone, // fork-hook: project-windows/ssh-prompts-window-identity
99100
listWindows: Effect.succeed([]), // fork-hook: multi-window/window-id-list

0 commit comments

Comments
 (0)