M4.36: Background Save and Export write a snapshot off the UI thread with status bar progress

- With Preferences > File Handling > Enable Background Save / Export on, File >
  Save, Save As, Save a Copy and exports encode and write a snapshot of the
  document on a worker thread; the call returns at once ({path, background}).
- The status bar shows a spinner and what is being written; ui.inspect lists
  the running jobs under `background`.
- The document takes the path and counts as saved as of the snapshot once the
  file is written: edits made meanwhile keep it modified.
- Quit and Close wait for running saves; the Save Changes dialog saves at once.
- The host gives a thread-safe writer (Services::write_shared, atomic on the
  desktop); without one (web, tests) everything runs at once as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-05 12:27:06 +07:00
co-authored by Claude Opus 5.5
parent 65cdc45ed9
commit db0a7ffd8b
14 changed files with 590 additions and 94 deletions
+9
View File
@@ -163,6 +163,11 @@ impl DocState {
pub fn mark_saved(&mut self) {
self.saved_doc = self.doc.clone();
}
/// Record `snapshot` (the document as a background save took it) as saved: edits made since
/// keep the document modified.
pub fn mark_saved_as(&mut self, snapshot: &Arc<Document>) {
self.saved_doc = snapshot.clone();
}
pub fn title(&self) -> String {
let name = self
.path
@@ -625,6 +630,10 @@ impl Session {
pub fn documents(&self) -> &[DocState] {
&self.docs
}
/// The open document with [`DocState::uid`] `uid` (it may have closed since it was looked up).
pub fn document_mut(&mut self, uid: u64) -> Option<&mut DocState> {
self.docs.iter_mut().find(|d| d.uid == uid)
}
pub fn active_index(&self) -> Option<usize> {
self.active
}