Disown AppKit window restoration — launches present welcome again instead of a windowless shell

macOS keeps Saved Application State per app, and on macOS 26 its mere
existence — even describing zero windows, which repeated dev kills
guarantee — counts as "a restored session": SwiftUI then treats every
scene's defaultLaunchBehavior as moot and presents nothing. The app
launched as a windowless shell with no way back, since windowOpener is
captured by the first scene that appears — so Open Recent, the
re-grant Grant click, and Dock reopen all silently buffered or
no-opped. Proven by -ApplePersistenceIgnoreState YES presenting
correctly on the same state; with the fix, welcome presented 3/3
consecutive plain launches.

Three changes:
- App.init registers ApplePersistenceIgnoreState — restoration is the
  registry's job (02 § Launch and window lifecycle), every scene
  already declares restorationBehavior(.disabled), and AppKit's layer
  was pure liability. Registered before NSApplicationMain runs, which
  is what makes a registration-domain default early enough.
- The restore bootstrap presents at every launch as the app's one
  reliable presenter; welcome is never system-presented (.suppressed)
  — the pass opens it when nothing else lands on screen.
  LaunchPlan.presentsBootstrap retired.
- captureWindowActions returns the replayed Finder-open count so the
  pass counts those as opens — a cold document launch doesn't get
  welcome stacked beside its board.

Both suites green, verify-editions 30/30.

Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
2026-07-29 22:48:04 -04:00
parent 546ed94412
commit 90954a47d6
5 changed files with 48 additions and 28 deletions
+26 -2
View File
@@ -41,6 +41,17 @@ struct KanbanApp: App {
private let launchPlan: LaunchPlan
init() {
// **AppKit window restoration is fully disowned** restore-at-launch is the registry's job
// (02-architecture.md § Launch and window lifecycle), every scene below declares
// `.restorationBehavior(.disabled)`, and left alive the machinery is actively harmful: AppKit
// counts its saved state (even a windowless one) as "a restored session", and SwiftUI then
// treats every `defaultLaunchBehavior` as moot the app launches with no windows at all and
// no way to get one, since `windowOpener` is captured by the first scene that appears
// (observed on macOS 26, 2026-07-29; `-ApplePersistenceIgnoreState YES` on the command line
// proved the mechanism). Registered here because `App.init` runs before `NSApplicationMain`,
// which is what makes a registration-domain default early enough for AppKit's read.
UserDefaults.standard.register(defaults: ["ApplePersistenceIgnoreState": true])
// Read first, because it decides *which app-side state the model is built over* a fixture
// launch keeps its recents and its clipboard snapshots in the scratch directory rather than in
// the shared App Group container.
@@ -73,7 +84,12 @@ struct KanbanApp: App {
.environment(appModel)
.captureWindowActions(into: appModel)
}
.defaultLaunchBehavior(launchPlan == .welcome ? .automatic : .suppressed)
// **Never presented by the system** the restore bootstrap below opens welcome through
// `AppModel.showWelcome()` when the launch pass ends with nothing else on screen. `.automatic`
// was tried here (conditioned on the plan) and macOS 26 answered it by presenting *no scene at
// all*: not welcome, not even a `.presented` bootstrap a windowless launch with no way back,
// since `windowOpener` is captured by the first scene that appears. One presenter, one rule.
.defaultLaunchBehavior(.suppressed)
.restorationBehavior(.disabled)
// "Welcome: resizable, no title bar (background drag)" (03-board-ui.md § Welcome screen &
// templates). `.contentMinSize` rather than `.contentSize`, because the view states a
@@ -104,7 +120,15 @@ struct KanbanApp: App {
.environment(appModel)
.captureWindowActions(into: appModel)
}
.defaultLaunchBehavior(launchPlan.presentsBootstrap ? .presented : .suppressed)
// **Presented at every launch, whatever the plan** the bootstrap is the app's one reliable
// way to put a window on screen. Welcome's `.automatic` above is a request the system is free
// to decline, and on macOS 26 it does: a launch with nothing to restore presented *no* scene
// at all, which left `windowOpener` uncaptured and the app a windowless shell no menu action
// could revive (observed 2026-07-29; the per-edition open-now flags exposed it, because before
// them a flagged board almost always routed launches through this window). The pass itself
// still dispatches on the plan a `.welcome` launch restores nothing and shows welcome
// and this window stays invisible and dismisses itself either way.
.defaultLaunchBehavior(.presented)
.restorationBehavior(.disabled)
.windowStyle(.plain)
.defaultSize(width: 1, height: 1)