Architecture

Sessions & Workspaces

Window management, tab restoration, and state persistence
Properties3
Is BaseNo
Iconi-lucide-layout-grid
Order30

Workspaces

Each native macOS window and each native tab is backed by a KytosWorkspace — an @Observable model holding a split tree of panes plus the focused pane.

KytosAppModel manages the mapping from window/tab UUIDs to workspaces.

Persistence

At shutdown, Kytos persists:

  • KytosAppModel_Windows_v7 — the full workspace map (all windows, all panes)
  • KytosAppModel_TabGroups_v1 — native tab groupings

On relaunch:

  1. SwiftUI/AppKit restores each NSWindow via state restoration
  2. Each window's UUID is restored by WindowGroup(for: UUID.self)
  3. KytosAppModel.workspace(for:) reconnects the UUID to its workspace
  4. UUID remapping handles cases where SwiftUI assigns new UUIDs on restore
  5. Tab groups are replayed via addTabbedWindow after windows register

Tab Restoration

Tab restoration uses a retry loop (attemptPendingTabRestoration) that:

  1. Fires every 0.1s, up to 40 attempts
  2. Waits for all windows in a group to register
  3. Orders them front
  4. Groups them with addTabbedWindow
  5. Skips if AppKit already grouped them

restoredWindowIDRemap and remapPendingTabGroups keep tab group data consistent when UUIDs change during restoration.

Widget Snapshots

KytosAppModel writes a JSON snapshot to the widget's sandbox container after state changes:

~/Library/Containers/me.jwintz.Kytos.KytosWidget/Data/Library/Application Support/Kytos/widget-snapshot.json

WidgetCenter.shared.reloadAllTimelines() is called immediately after writing.