Skip to content

Commit 76fc8a6

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
feat(desktop): update relaunch restores every window from manifest v2
## What Changed | Area | Change | | --- | --- | | Manifest | v2: one row per window, `{ windowId, route, bounds?, workspace? }` | | Restore | keyed by `windowId`; extra windows open via `createNew` | | Bounds | the current main window saves them, and hands over on close | | Token | only a window restored onto a workspace maps as `t3code-window-<WindowId>` | | Rules | every rule staged on a token is removed when placement ends | | Claims | exact title, else the one new client since show; atomic select and record | ## Why Update relaunch dropped extra hub and same-project windows. A New Window that became main never saved its bounds. ## Close conditions ### Manifest - [x] **Route:** an invalid route falls back to `/` - [x] **v1 project entry:** becomes a seeded window - [x] **v1 hub entry:** becomes an all-projects window - [x] **Bounds:** display-validated - [x] **When:** update relaunch only - [x] **Corrupt manifest:** still opens one window ### Placement - [x] **Token:** the title carries the WindowId until claimed - [x] **Claims:** serialized, never guessed - [ ] **Live:** real Hyprland update relaunch Placement boxes are proven against a faked compositor; the host arranges live proof. ### Notes | Note | Detail | | --- | --- | | `project` field | required: a route alone cannot tell a project window from an all-projects one | | Token scope | other windows keep their normal title, so user rules on it still fire | | Rule cleanup | Lua: workspace and suppression rules disabled, handle globals cleared | | Rule names | one compositor-wide counter; no name is ever reused | | Legacy grammar | no unset for `suppress_event`, so tokens stage workspace only | | No claim lock | select and record are atomic by construction | | Known limit | all-projects windows without bounds open stacked at main's bounds | | Known limit | two normal windows mapping at once, both retitled, stay unclaimed | ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [ ] I included before/after screenshots for any UI changes (none) - [ ] I included a video for animation/interaction changes (none) Closes #1345 Written by Claude Opus 5.5 in Claude Code, hosted by T3 Code. ## Fork trailers Squashes: - adf1305 feat(desktop): update relaunch restores every window from manifest v2 (#1577) - d40e3ab fixup! feat(desktop): update relaunch restores every window from manifest v2 - 4d5a32f feat(desktop): update relaunch restores every window from manifest v2 (#1577) - faa53bd refactor(multi-window): createWindow seams become marked insertions (#1811) (#1811) Fork-Domain: multi-window Fork-Tier: core
1 parent 25ca799 commit 76fc8a6

19 files changed

Lines changed: 1329 additions & 186 deletions

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ import type { WindowRequest } from "../window/WindowDispatch.fork.ts";
1414
import { makeSecondInstanceBuffer } from "./DesktopSecondInstanceBuffer.fork.ts";
1515

1616
const noopServices: StartupDrainServices = {
17-
hyprlandPlacement: {
18-
isAvailable: false,
19-
claim: () => Effect.void,
20-
forget: () => Effect.void,
21-
workspaceOf: () => Effect.succeedNone,
22-
stageWorkspaceRule: () => Effect.succeed(false),
23-
clearWorkspaceRule: () => Effect.void,
24-
moveToWorkspace: () => Effect.void,
25-
},
2617
windowSession: { capture: () => Effect.void, consume: Effect.succeed([]) },
2718
};
2819

@@ -65,7 +56,7 @@ describe("DesktopSecondInstanceBuffer", () => {
6556
request.kind === "project-link" ? request.ref.projectId : request.kind,
6657
]);
6758
const openers: WindowOpeners = {
68-
ensureIdentity: () => () => Effect.die("no restore is staged"),
59+
restore: () => () => Effect.die("no restore is staged"),
6960
dispatch: () => record,
7061
createMainIfBackendReady: () => Effect.void,
7162
};

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ describe("ElectronWindow", () => {
121121
assert.notStrictEqual(project.windowId, hub.windowId);
122122
assert.notStrictEqual(project.windowId, String(projectWindow.id));
123123
assert.deepEqual(yield* electronWindow.getById(project.windowId), Option.some(projectWindow));
124+
// A window that cannot report its route or bounds reopens at its home.
124125
assert.deepEqual(yield* electronWindow.listWindows, [
125-
{ windowId: project.windowId, identity: projectIdentity },
126-
{ windowId: hub.windowId, identity: HUB_WINDOW_IDENTITY },
126+
{ windowId: project.windowId, identity: projectIdentity, route: "/", bounds: null },
127+
{ windowId: hub.windowId, identity: HUB_WINDOW_IDENTITY, route: "/", bounds: null },
127128
]);
128129
projectWindow.__emit("closed");
129130
assert.isTrue(Option.isNone(yield* electronWindow.getById(project.windowId)));
@@ -151,6 +152,40 @@ describe("ElectronWindow", () => {
151152
assert.deepEqual(yield* electronWindow.getById(restoredId), Option.some(first));
152153
}).pipe(Effect.provide(TestLayer)),
153154
);
155+
it.effect("creates a restored window per id, even two on one identity", () =>
156+
Effect.gen(function* () {
157+
const firstId = "00000000-0000-4000-8000-00000000000b" as WindowId;
158+
const secondId = "00000000-0000-4000-8000-00000000000c" as WindowId;
159+
const first = Object.assign(makeBrowserWindow({ id: 40, destroyed: false }), {
160+
webContents: { getURL: () => "t3code://app/#/settings/general" },
161+
isFullScreen: () => false,
162+
isMaximized: () => true,
163+
isMinimized: () => false,
164+
getNormalBounds: () => ({ x: 10.4, y: 20, width: 1000, height: 700 }),
165+
getBounds: () => ({ x: 0, y: 0, width: 1920, height: 1080 }),
166+
});
167+
const second = makeBrowserWindow({ id: 41, destroyed: false });
168+
const electronWindow = yield* ElectronWindow.ElectronWindow;
169+
const one = yield* electronWindow.createNew(
170+
HUB_WINDOW_IDENTITY,
171+
() => Effect.succeed(first),
172+
firstId,
173+
);
174+
const two = yield* electronWindow.createNew(
175+
HUB_WINDOW_IDENTITY,
176+
() => Effect.succeed(second),
177+
secondId,
178+
);
179+
assert.deepEqual([one.windowId, two.windowId], [firstId, secondId]);
180+
// Capture reads the hash route and the unmaximized bounds.
181+
assert.deepEqual((yield* electronWindow.listWindows)[0], {
182+
windowId: firstId,
183+
identity: HUB_WINDOW_IDENTITY,
184+
route: "/settings/general",
185+
bounds: { x: 10, y: 20, width: 1000, height: 700 },
186+
});
187+
}).pipe(Effect.provide(TestLayer)),
188+
);
154189
it.effect("closes identities and removes windows destroyed externally", () =>
155190
Effect.gen(function* () {
156191
const projectIdentity = projectWindowIdentity(

‎apps/desktop/src/updates/DesktopUpdates.fork.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ describe("DesktopUpdates", () => {
1919
{
2020
windowId: "00000000-0000-4000-8000-000000000001" as WindowId,
2121
identity: HUB_WINDOW_IDENTITY,
22+
route: "/",
23+
bounds: { x: 0, y: 0, width: 1200, height: 800 },
24+
},
25+
{
26+
windowId: "00000000-0000-4000-8000-000000000002" as WindowId,
27+
identity: projectIdentity,
28+
route: "/project/environment-1/project-1",
29+
bounds: null,
2230
},
23-
{ windowId: "00000000-0000-4000-8000-000000000002" as WindowId, identity: projectIdentity },
2431
];
2532
const harness = makeHarness({ openWindows });
2633
return Effect.scoped(

‎apps/desktop/src/window/DesktopStartupDrain.fork.test.ts‎

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,31 @@ import * as Ref from "effect/Ref";
1010
import * as Schema from "effect/Schema";
1111

1212
import * as ElectronWindow from "../electron/ElectronWindow.ts";
13-
import { HUB_WINDOW_IDENTITY, type WindowIdentity } from "./WindowIdentity.ts";
13+
import type { WindowIdentity } from "./WindowIdentity.ts";
1414
import {
1515
makeStartupDrain,
1616
type StartupDrainServices,
1717
type WindowOpeners,
1818
} from "./DesktopStartupDrain.fork.ts";
1919
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
20-
import type { WindowId } from "./WindowId.fork.ts";
21-
import type { WindowRequest } from "./WindowDispatch.fork.ts";
20+
import type { WindowRestoreEntry } from "./DesktopWindowSession.ts";
21+
import { windowIdentityForSeed, type WindowRequest } from "./WindowDispatch.fork.ts";
2222

2323
const fakeWindow = {} as Electron.BrowserWindow;
24-
const fakeWindowId = "00000000-0000-4000-8000-000000000001" as WindowId;
2524

26-
/** Adapts a window opener to the restore opener, which also reports the id. */
27-
const asEnsure =
28-
(open: () => (identity: WindowIdentity) => Effect.Effect<Electron.BrowserWindow>) =>
25+
const hubRestore: WindowRestoreEntry = {
26+
route: "/",
27+
seed: "all-projects",
28+
bounds: null,
29+
workspace: null,
30+
};
31+
32+
/** Adapts an identity opener to the restore opener. */
33+
const asRestore =
34+
<E>(open: () => (identity: WindowIdentity) => Effect.Effect<Electron.BrowserWindow, E>) =>
2935
() =>
30-
(identity: WindowIdentity) =>
31-
open()(identity).pipe(Effect.map((window) => ({ window, windowId: fakeWindowId })));
36+
(entry: WindowRestoreEntry) =>
37+
open()(windowIdentityForSeed(entry.seed));
3238

3339
const projectLink = (name: string): WindowRequest => ({
3440
kind: "project-link",
@@ -44,15 +50,6 @@ const requestKey = (request: WindowRequest): string =>
4450
const isElectronWindowCreateError = Schema.is(ElectronWindow.ElectronWindowCreateError);
4551

4652
const noopServices: StartupDrainServices = {
47-
hyprlandPlacement: {
48-
isAvailable: false,
49-
claim: () => Effect.void,
50-
forget: () => Effect.void,
51-
workspaceOf: () => Effect.succeedNone,
52-
stageWorkspaceRule: () => Effect.succeed(false),
53-
clearWorkspaceRule: () => Effect.void,
54-
moveToWorkspace: () => Effect.void,
55-
},
5653
windowSession: {
5754
capture: () => Effect.void,
5855
consume: Effect.succeed([]),
@@ -78,7 +75,7 @@ const makeRecordingOpeners = Effect.gen(function* () {
7875
);
7976
yield* Deferred.succeed(gate, undefined);
8077
const openers: WindowOpeners = {
81-
ensureIdentity: asEnsure(() => (identity) => record(keyOf(identity))),
78+
restore: asRestore(() => (identity) => record(keyOf(identity))),
8279
dispatch: () => (request) => record(requestKey(request)).pipe(Effect.asVoid),
8380
createMainIfBackendReady: () =>
8481
Ref.update(opened, (keys) => [...keys, "hub"]).pipe(Effect.asVoid),
@@ -105,7 +102,7 @@ describe("DesktopStartupDrain", () => {
105102
return fakeWindow;
106103
});
107104
const openers: WindowOpeners = {
108-
ensureIdentity: asEnsure(pausingEnsure),
105+
restore: asRestore(pausingEnsure),
109106
dispatch: () => (request) => Ref.update(opened, (keys) => [...keys, requestKey(request)]),
110107
createMainIfBackendReady: () => Effect.void,
111108
};
@@ -114,7 +111,7 @@ describe("DesktopStartupDrain", () => {
114111
...noopServices,
115112
windowSession: {
116113
capture: () => Effect.void,
117-
consume: Effect.succeed([{ identity: HUB_WINDOW_IDENTITY, workspace: null }]),
114+
consume: Effect.succeed([hubRestore]),
118115
},
119116
});
120117
const drainFiber = yield* drain.drain(noopServices, () => openers).pipe(Effect.forkDetach);
@@ -146,7 +143,7 @@ describe("DesktopStartupDrain", () => {
146143
}
147144
});
148145
const openers: WindowOpeners = {
149-
ensureIdentity: asEnsure(() => () => Effect.succeed(fakeWindow)),
146+
restore: asRestore(() => () => Effect.succeed(fakeWindow)),
150147
dispatch: pausingDispatch,
151148
createMainIfBackendReady: () => Effect.void,
152149
};
@@ -180,7 +177,7 @@ describe("DesktopStartupDrain", () => {
180177
yield* Deferred.await(release);
181178
});
182179
const openers: WindowOpeners = {
183-
ensureIdentity: asEnsure(() => () => Effect.succeed(fakeWindow)),
180+
restore: asRestore(() => () => Effect.succeed(fakeWindow)),
184181
dispatch: pausingDispatch,
185182
createMainIfBackendReady: () => Effect.void,
186183
};
@@ -261,6 +258,52 @@ describe("DesktopStartupDrain", () => {
261258
}),
262259
);
263260

261+
it.effect("still opens one window when every restored window fails", () =>
262+
Effect.gen(function* () {
263+
const drain = yield* makeStartupDrain;
264+
const fakes = yield* makeRecordingOpeners;
265+
const openers: WindowOpeners = {
266+
...fakes.openers,
267+
restore: () => () =>
268+
Effect.fail(
269+
new ElectronWindow.ElectronWindowCreateError({
270+
options: {
271+
title: null,
272+
width: null,
273+
height: null,
274+
minWidth: null,
275+
minHeight: null,
276+
show: null,
277+
modal: null,
278+
frame: null,
279+
transparent: null,
280+
backgroundColor: null,
281+
webPreferences: {
282+
preload: null,
283+
partition: null,
284+
backgroundThrottling: null,
285+
sandbox: null,
286+
contextIsolation: null,
287+
nodeIntegration: null,
288+
webviewTag: null,
289+
},
290+
},
291+
cause: new Error("simulated restore failure"),
292+
}),
293+
),
294+
};
295+
yield* drain.stageRestore({
296+
windowSession: {
297+
capture: () => Effect.void,
298+
consume: Effect.succeed([hubRestore, { ...hubRestore, route: "/settings" }]),
299+
},
300+
});
301+
yield* drain.drain(noopServices, () => openers);
302+
// The cold-start fallback: a restore that opened nothing is no restore.
303+
assert.deepEqual(yield* Ref.get(fakes.opened), ["hub"]);
304+
}),
305+
);
306+
264307
it.effect("never reveals a window for a second launch queued during boot", () =>
265308
Effect.gen(function* () {
266309
const drain = yield* makeStartupDrain;

‎apps/desktop/src/window/DesktopWindow.fork.suite.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { WINDOW_DEMAND_STATE_CHANNEL } from "../ipc/channels.ts";
1616
import type * as PreviewManager from "../preview/Manager.ts";
1717
import type { DesktopWindowHarnessFork } from "./DesktopWindow.test.ts";
1818
import * as DesktopWindow from "./DesktopWindow.ts";
19-
import { testWindowId } from "./testWindowIds.fork.ts";
19+
import { testRestoreEntry, testWindowId } from "./testWindowIds.fork.ts";
2020

2121
/**
2222
* Upstream's test environment plus the variables a fork case opts into. The
@@ -306,4 +306,31 @@ export const registerDesktopWindowForkTests = (harness: DesktopWindowHarnessFork
306306
}).pipe(Effect.provide(layer));
307307
}),
308308
);
309+
310+
it.effect("leaves an unplaced restored window wherever Hyprland puts it", () =>
311+
Effect.gen(function* () {
312+
const fakeWindow = makeFakeBrowserWindow();
313+
const createCount = yield* Ref.make(0);
314+
const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
315+
const workspaceMoves: { key: string; workspace: string }[] = [];
316+
const layer = makeTestLayer({
317+
window: fakeWindow.window,
318+
createCount,
319+
mainWindow,
320+
workspaceMoves,
321+
restoreEntries: [testRestoreEntry("all-projects", null)],
322+
});
323+
324+
yield* Effect.gen(function* () {
325+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
326+
yield* desktopWindow.restoreWindowSession;
327+
yield* desktopWindow.openArguments(["t3code"]);
328+
yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
329+
330+
assert.equal(yield* Ref.get(createCount), 1);
331+
yield* Effect.yieldNow;
332+
assert.deepEqual(workspaceMoves, []);
333+
}).pipe(Effect.provide(layer));
334+
}),
335+
);
309336
};

0 commit comments

Comments
 (0)