Skip to content

Save window layout on close with modal prompt #82

@kordless

Description

@kordless

Goal

When the user closes a Hyperia window, prompt them to save the current layout. On Yes, persist the layout under a stable per-window key in electron-store. On No, clear any previously saved layout for that window. On Cancel, abort the close.

Scope

  • Intercept the close event on each BrowserWindow (currently app/ui/window.ts:521 clean())
  • Show a dialog.showMessageBox with three buttons: Save, Don't Save, Cancel
  • On Save: serialize the window's full layout state (see below) to electron-store under windowLayouts[windowUid]
  • On Don't Save: delete windowLayouts[windowUid]
  • On Cancel: event.preventDefault() and abort close

Window identity

Each window needs a UID stable across launches. Approach:

  • On window creation (app/ui/window.ts:67), generate a UUID and attach it to the window object
  • On restore from saved layout, reuse the original UUID from the saved entry
  • Use this UID as the key in windowLayouts

What gets serialized

type SavedLayout = {
  windowUid: string;
  position: [number, number];
  size: [number, number];
  termGroups: ITermGroup[];           // full BSP tree from Redux
  activeSessionUid: string;
  cwds: Record<string, string>;       // sessionUid → cwd
  webUrls: Record<string, string>;    // sessionUid → URL (see #N web panes)
  stickyIds: string[];                // see #N sticky binding
  savedAt: number;
};

Implementation notes

  • Layout state (termGroups) lives in the renderer's Redux store — needs an IPC roundtrip on close to dump state from renderer to main before the close completes
  • Add a new RPC: 'get layout snapshot' that the main process sends to the renderer, which replies with the serialized termGroups + active session
  • bridge.ts already tracks BSP geometry per session — but full split tree shape lives in renderer

Files touched

  • app/ui/window.ts — close handler, modal, IPC roundtrip
  • app/config/windows.ts — extend with windowLayouts accessor
  • typings/hyper.d.ts — add SavedLayout type
  • lib/index.tsx or renderer entry — handle 'get layout snapshot' RPC

Out of scope

Restore is #N (separate issue). Sticky binding and web pane URLs are #N and #N.

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