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
+11 -3
View File
@@ -39,13 +39,21 @@ struct NativeOptions {
preview: bool,
}
/// The `.vectorcraft` file of `doc` with the options in `p`.
pub(super) fn encode(cmd: &str, f: &Format, doc: &Document, p: &Value) -> Result<Vec<u8>> {
/// The options in `p` for saving `doc`, checked (the preview is left to [`encode`]) → them and
/// whether to embed a preview.
pub(super) fn save_options(cmd: &str, f: &Format, doc: &Document, p: &Value) -> Result<(SaveOptions, bool)> {
let o: NativeOptions = super::encode::options(f, p)?;
let mut so = SaveOptions::for_doc(doc);
so.compress = o.compress.unwrap_or(false);
so.version = o.version.unwrap_or(vectorcraft_format::VERSION);
if o.preview {
so.check().map_err(|e| bad(cmd, e.to_string()))?;
Ok((so, o.preview))
}
/// The `.vectorcraft` file of `doc` with the options in `p`.
pub(super) fn encode(cmd: &str, f: &Format, doc: &Document, p: &Value) -> Result<Vec<u8>> {
let (mut so, preview) = save_options(cmd, f, doc, p)?;
if preview {
so.preview = preview_png(doc)?;
}
vectorcraft_format::save_with(doc, &so).map_err(|e| bad(cmd, e.to_string()))