Save the layout tree (tabs + splits + focus + ratios) to localStorage, debounced, on every structural/focus/resize change; restore it on boot. Load rebuilds with fresh node ids and defensively drops malformed data — a corrupt or versioned-out blob falls back to a single empty tab. Sessions that no longer exist when restored aren't pruned eagerly (the session list isn't known at boot); their panes attach, the broker closes the dead socket, and the pane auto-closes. Closes #34. Part of epic #37. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+20
-3
@@ -5,6 +5,7 @@ import { CatalogStore } from "./events.js";
|
||||
import { mountHud, type Hud } from "./hud.js";
|
||||
import { emptyLayout, type Layout, openSessions } from "./layout.js";
|
||||
import { createMultiView, type MultiView } from "./multiview.js";
|
||||
import { loadLayout, saveLayout } from "./persistence.js";
|
||||
import { openSpawnModal } from "./spawn.js";
|
||||
import { initTheme } from "./theme.js";
|
||||
import { sessionName } from "./types.js";
|
||||
@@ -106,8 +107,16 @@ hud = mountHud(root, store, () => pool.focused());
|
||||
|
||||
// ---- layout state ----
|
||||
// Single source of truth for what's mounted: tabs of split trees. The hash route
|
||||
// is just a deep-link into it (`#/attach/:id` focuses/opens a session).
|
||||
const layout: Layout = emptyLayout();
|
||||
// is just a deep-link into it (`#/attach/:id` focuses/opens a session). Restored
|
||||
// from localStorage per device (issue #34); dead sessions self-prune on attach.
|
||||
const layout: Layout = loadLayout() ?? emptyLayout();
|
||||
|
||||
// Debounced persist — the controller calls this after every layout change.
|
||||
let saveTimer: number | undefined;
|
||||
function scheduleSave(): void {
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = window.setTimeout(() => saveLayout(layout), 400);
|
||||
}
|
||||
|
||||
function infoFor(sessionId: string) {
|
||||
const s = store.snapshot().sessions.get(sessionId);
|
||||
@@ -155,7 +164,15 @@ function renderNotFound(raw: string): HTMLElement {
|
||||
|
||||
// The multi-view controller renders tabs + splits inside the content pane and
|
||||
// mounts a live attach into each session leaf.
|
||||
mv = createMultiView({ pool, layout, sidebar, infoFor, onDisconnect: closePane, renderWelcome });
|
||||
mv = createMultiView({
|
||||
pool,
|
||||
layout,
|
||||
sidebar,
|
||||
infoFor,
|
||||
onDisconnect: closePane,
|
||||
renderWelcome,
|
||||
onLayoutChange: scheduleSave,
|
||||
});
|
||||
let contentShowsMv = false;
|
||||
function showMultiView(): void {
|
||||
if (!contentShowsMv) {
|
||||
|
||||
Reference in New Issue
Block a user