Skip to content

Restore window layouts on app launch #83

@kordless

Description

@kordless

Goal

On app startup, read all saved layouts from electron-store (windowLayouts key) and recreate each window with its saved tabs, panes, cwds, and active session.

Scope

  • After app.on('ready') fires and the sidecar is up (app/index.ts:330), iterate windowLayouts entries
  • For each entry: create a BrowserWindow at the saved position/size, wait for renderer load, then drive a sequence of RPC calls to recreate the layout
  • Reuse the saved windowUid so the next save round-trips to the same slot

Restoration sequence per window

  1. Open window with saved position/size
  2. Wait for renderer ready
  3. For each tab in saved layout:
    • Send RPC 'create tab' with saved tabName
    • For each pane in the tab's BSP tree (root → leaves):
      • If root: spawn shell with cwd from saved cwds[sessionUid]
      • If split: send RPC 'split pane' with parent UID, direction, sizes
      • If web pane: send RPC 'open web pane' with URL from saved webUrls[sessionUid]
  4. Send RPC 'set active session' with saved activeSessionUid

Existing primitives

  • app/ui/window.ts:189 createSession() already supports cwd option — pass through saved cwd
  • bridge.ts:718 updateSessionLayout() flows BSP coords back; should round-trip cleanly
  • Web pane creation already exists via /api/web-pane and renderer webUrl handling

New RPC handlers needed (renderer side)

  • 'replay tab' — create a tab with given name + initial cwd
  • 'replay split' — split a given pane in a given direction with given sizes
  • 'replay web pane' — open a web pane in a given pane slot with given URL
  • 'replay set active' — set the active session

These are thin wrappers around existing Redux actions (split, setActive, etc.).

Edge cases

  • Saved cwd no longer exists → fall back to home directory (existing createSession already validates with existsSync)
  • Saved layout references a window position off-screen → clamp via existing windowUtils.positionIsValid()
  • Multiple saved windows → open them sequentially to avoid race conditions

Files touched

  • app/index.ts — startup hook reads layouts and orchestrates restore
  • lib/index.tsx or renderer entry — handle replay RPCs
  • lib/actions/term-groups.ts — may need a replaySplit action that takes explicit sizes

Depends on

#82 (save layout) — without saved data there's nothing to restore

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions