fix(editor): quit rides the departure gate
shutdown() flushed both sessions best-effort and ignored the results — quitting with an unanswered #67 conflict wrote local text over the foreign disk body (flush() holds for conflicts only in the debounce), and a failed quit-time flush silently dropped the only copy of the edits. Quit now routes through the same departure gate as navigation: documentsMayDepart runs both sessions through sessionMayDepart, and the failed-flush-at-quit posture is BLOCK QUIT — applicationShouldTerminate (quitReply(posts:), before the Cold Turkey ask) refuses termination with one spoken reason via a hosted-guarded alert. PostsModel.active (weak, registered by AppGateState.init — the WritingLockState.active precedent) is the delegate's reachability. Finish-audit fixes folded in: sessionMayDepart refuses a never-loaded session's retyped words (its flush is a vacuous success — the same gap closed for navigation); shutdown stays void (no production reader of a Bool). +5 pins (conflict hold, clean flush, guest flush, never-loaded refusal, delegate refusal incl. chmod-injected flush failure), all flip-verified. Rail 708/708; format+lint clean. Closes #200
This commit is contained in:
1 parent
55be3d1a2f
commit
2334afc392
6 files changed
+198
-2
No files matched your search
@@ -332,9 +332,19 @@ enum WritingLockKiosk {
|
||||
/// unlocked quits proceed, a held block gets ONE modal ask — walk away
|
||||
/// (the block dies quietly with the process, nothing kept — #158 settle
|
||||
/// 3) or keep writing.
|
||||
/// #200: quit is also a document departure — the posts gate runs FIRST
|
||||
/// (never walk away from a block the quit then refuses to complete): an
|
||||
/// open document that can't depart (unanswered #67 conflict, failed
|
||||
/// flush) refuses termination with one spoken reason.
|
||||
@MainActor
|
||||
final class WritingLockAppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationShouldTerminate(_: NSApplication) -> NSApplication.TerminateReply {
|
||||
// #200: the departure gate — before the lock ask, so a refusal
|
||||
// never strands a walked-away block in a still-running app.
|
||||
guard quitReply(posts: PostsModel.active) == .terminateNow else {
|
||||
presentQuitRefusal()
|
||||
return .terminateCancel
|
||||
}
|
||||
guard WritingLockState.active?.isLocked == true else { return .terminateNow }
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Walk away from the block?"
|
||||
@@ -350,4 +360,27 @@ final class WritingLockAppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
return .terminateCancel
|
||||
}
|
||||
|
||||
/// #200: the quit-time departure gate — the pure decision, no UI (the
|
||||
/// pins' seam; the refusal alert below is hosted-guarded like the
|
||||
/// kiosk). nil posts (no model alive) passes: nothing is open,
|
||||
/// nothing to lose.
|
||||
func quitReply(posts: PostsModel?) -> NSApplication.TerminateReply {
|
||||
guard let posts else { return .terminateNow }
|
||||
guard posts.documentsMayDepart() else { return .terminateCancel }
|
||||
return .terminateNow
|
||||
}
|
||||
|
||||
/// #200: the refusal speaks (#163's ruling — self-aware friction, not
|
||||
/// silence): one alert naming the strip's reason. Hosted tests never
|
||||
/// present (the startLaunchCheck guard convention).
|
||||
private func presentQuitRefusal() {
|
||||
guard ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] == nil else { return }
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Quit stopped — a piece needs you first"
|
||||
alert.informativeText = PostsModel.active?.lastError
|
||||
?? "An open piece could not be saved. Tend to it, then quit again."
|
||||
alert.addButton(withTitle: "Back to Museion")
|
||||
alert.runModal()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user