feat(web): persist browser state

Keep settings, aliases, and recent drawings across browser sessions.

Load Start-page videos from a Pages-generated snapshot.
This commit is contained in:
Hakan Seven committed 2026-07-29 00:44:00 +03:00
1 parent 25166b9508
commit d4e792b2bc
15 files changed
+546 -88

No files matched your search

+30 -5
View File
@@ -1,7 +1,7 @@
//! Recent-files list backing the Start page's Recent Documents panel. The list
//! itself lives in the consolidated app config (`settings.json`, the "recent"
//! section); this module just mutates the in-memory list and persists via
//! `save_config`.
//! itself lives in the consolidated app config (native `settings.json` or web
//! `localStorage`, in the "recent" section); this module mutates the in-memory
//! list, persists it via `save_config`, and evicts matching web OPFS copies.
use super::OpenCADStudio;
use std::path::{Path, PathBuf};
@@ -17,7 +17,10 @@ impl OpenCADStudio {
pub(super) fn push_recent(&mut self, path: PathBuf) -> iced::Task<crate::app::Message> {
self.recent_files.retain(|r| r != &path);
self.recent_files.insert(0, path);
self.recent_files.truncate(self.recent_limit);
let evicted = self
.recent_files
.split_off(self.recent_limit.min(self.recent_files.len()));
remove_cached_copies(evicted);
self.save_config();
self.refresh_recent_thumbs()
}
@@ -68,6 +71,7 @@ impl OpenCADStudio {
/// Drop a path from the recents list (manual removal from the Start page).
pub(super) fn remove_recent(&mut self, path: &Path) {
self.recent_files.retain(|r| r.as_path() != path);
remove_cached_copies([path.to_path_buf()]);
self.save_config();
}
@@ -75,7 +79,28 @@ impl OpenCADStudio {
/// persist both.
pub(super) fn set_recent_limit(&mut self, limit: usize) {
self.recent_limit = limit.clamp(RECENT_MIN, RECENT_MAX);
self.recent_files.truncate(self.recent_limit);
let evicted = self
.recent_files
.split_off(self.recent_limit.min(self.recent_files.len()));
remove_cached_copies(evicted);
self.save_config();
}
}
fn remove_cached_copies(paths: impl IntoIterator<Item = PathBuf>) {
#[cfg(not(target_arch = "wasm32"))]
let _ = paths;
#[cfg(target_arch = "wasm32")]
for path in paths {
let Some(name) = path
.file_name()
.map(|name| name.to_string_lossy().into_owned())
else {
continue;
};
wasm_bindgen_futures::spawn_local(async move {
let _ = crate::io::web_recent::remove(&name).await;
});
}
}