Clear crash-recovery draft on save, not just on discard

attemptSaveCurrentConversation() (Save/Save As) and confirmDiscardIfNeeded's
no-unsaved-changes early return both left the on-disk draft_conversation.json
untouched, so a stale snapshot from before the save lingered and triggered
"Restore unsaved conversation?" on next launch even though everything had
already been saved with no changes since.
This commit is contained in:
2026-08-19 12:52:21 +02:00
parent f5fd09ac33
commit d46fb03a07
+11 -1
View File
@@ -756,6 +756,7 @@ Don't narrate future actions ("Let me...") - just use the tools.
savedMessageCount = chatMessages.count
notesEnabled = false
notesFilename = nil
DraftRecoveryService.shared.clear()
showSystemMessage("Saved as \"\(details.name)\"")
Task { await GitSyncService.shared.autoSync() }
} catch {
@@ -2359,7 +2360,14 @@ Don't narrate future actions ("Let me...") - just use the tools.
/// discards the crash-recovery draft and proceeds; Cancel calls `onCancel()` the caller's
/// original action (new chat / clear / switch / quit) must not happen.
func confirmDiscardIfNeeded(then proceed: @escaping () -> Void, onCancel: @escaping () -> Void = {}) {
guard hasUnsavedChanges else { proceed(); return }
guard hasUnsavedChanges else {
// Nothing unsaved means any on-disk crash-recovery draft is now stale (either a
// save already covered it, or there was nothing worth mirroring) clear it so the
// next launch doesn't offer to "restore" a conversation that's already saved intact.
DraftRecoveryService.shared.clear()
proceed()
return
}
let alert = NSAlert()
alert.alertStyle = .warning
@@ -2401,6 +2409,7 @@ Don't narrate future actions ("Let me...") - just use the tools.
id: id, name: name, messages: chatMessages, primaryModel: selectedModel?.id
)
savedMessageCount = chatMessages.count
DraftRecoveryService.shared.clear()
showSystemMessage("Saved \"\(name)\"")
Task { await GitSyncService.shared.autoSync() }
return true
@@ -2421,6 +2430,7 @@ Don't narrate future actions ("Let me...") - just use the tools.
savedMessageCount = chatMessages.count
notesEnabled = false
notesFilename = nil
DraftRecoveryService.shared.clear()
showSystemMessage("Saved as \"\(details.name)\"")
Task { await GitSyncService.shared.autoSync() }
return true