forked from 1b-agent/opencadstudio-upstream
web: autosave snapshots with crash-recovery restore, persistent storage
The web build had no autosave: on_autosave was a no-op and the
subscription was native-only. Both gates are gone; every savetime tick
now serializes each dirty tab (same pre-serialize sync as the web save
path, no thumbnail, serialized serially off the critical paint path)
into a dedicated opencadstudio-autosave OPFS directory, keyed by
drawing name, without touching the dirty flag, downloads, or recents.
On boot the web app scans that directory and offers any snapshot
newer than the last saved copy in a localized Recover Drawing modal
(Restore opens it as "name (recovered).dwg" through the standard
open pipeline; Discard removes it; Escape discards). Saving or
closing a drawing clears its snapshot; the boot scan also garbage-
collects stale entries. run_web now requests navigator.storage.persist
so settings and OPFS data survive browser eviction.
(cherry picked from commit 101d167ebc)
This commit is contained in:
1 parent
6cb8c00fa0
commit
12fd04790f
31 files changed
+747
-12
No files matched your search
+18
-1
@@ -1249,6 +1249,17 @@ impl OpenCADStudio {
|
||||
}
|
||||
},
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::WebAutosavesScanned(result) => self.on_web_autosaves_scanned(result),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::WebAutosaveRestore => self.on_web_autosave_restore(),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::WebAutosaveDiscard => self.on_web_autosave_discard(),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::WebAutosaveBytes(name, result) => self.on_web_autosave_bytes(name, result),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Message::WebAutosaveSnapshotFinished(result) => self.on_web_autosave_finished(result),
|
||||
|
||||
Message::ImagePick => {
|
||||
Task::perform(crate::io::pick_image_file(), Message::ImagePickResult)
|
||||
}
|
||||
@@ -8953,6 +8964,12 @@ impl OpenCADStudio {
|
||||
if self.active_modal == Some(super::ModalKind::Options) {
|
||||
return self.update(Message::OptionsClose);
|
||||
}
|
||||
// Closing the crash-recovery prompt (✕ or Escape) discards
|
||||
// the offered snapshot — otherwise it would requeue itself.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if self.active_modal == Some(super::ModalKind::AutosaveRestore) {
|
||||
return self.update(Message::WebAutosaveDiscard);
|
||||
}
|
||||
// Closing the shortcut editor with un-applied rows needs an
|
||||
// explicit discard; a second close attempt (or the overlay's
|
||||
// Discard button) goes through.
|
||||
@@ -10047,7 +10064,7 @@ impl OpenCADStudio {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
Task::perform(
|
||||
crate::io::pdf_export::pick_pdf_path_owned(stem),
|
||||
crate::io::pdf_export::pick_plot_path_owned(stem),
|
||||
Message::PrintAllPdfPath,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user