Description
Session state changed shortly before quitting CastCodes is lost. The app only persists workspace snapshots on ambient events (window move/resize/focus/close, tab changes flushed by the persistence writer's event stream). On shutdown, on_will_terminate terminated the SQLite persistence writer without first saving app state, so any state not yet captured by an ambient save — e.g. a tab opened right before quitting — is missing when the session is restored on next launch.
Steps to reproduce
- Enable session restoration (default: on).
- Open a new tab (or otherwise change workspace state).
- Quit the app immediately (Cmd+Q) without moving/resizing the window first.
- Relaunch.
Expected: the restored session includes the tab opened in step 2.
Actual: the restored session reflects the last ambient save; the new tab is missing.
Root cause
on_will_terminate in app/src/lib.rs called PersistenceWriter::terminate() directly. terminate() sends ModelEvent::Terminate and joins the writer thread — but no final ModelEvent::Snapshot was enqueued first, so the writer shut down with stale state.
Fix
Enqueue a final snapshot save before terminating the writer, so the terminate/join guarantees the snapshot is flushed to SQLite before the process exits.
Description
Session state changed shortly before quitting CastCodes is lost. The app only persists workspace snapshots on ambient events (window move/resize/focus/close, tab changes flushed by the persistence writer's event stream). On shutdown,
on_will_terminateterminated the SQLite persistence writer without first saving app state, so any state not yet captured by an ambient save — e.g. a tab opened right before quitting — is missing when the session is restored on next launch.Steps to reproduce
Expected: the restored session includes the tab opened in step 2.
Actual: the restored session reflects the last ambient save; the new tab is missing.
Root cause
on_will_terminateinapp/src/lib.rscalledPersistenceWriter::terminate()directly.terminate()sendsModelEvent::Terminateand joins the writer thread — but no finalModelEvent::Snapshotwas enqueued first, so the writer shut down with stale state.Fix
Enqueue a final snapshot save before terminating the writer, so the terminate/join guarantees the snapshot is flushed to SQLite before the process exits.