diff --git a/apps/solidcraft-web/src/main.rs b/apps/solidcraft-web/src/main.rs index 1c8ad471e..c66b56bd0 100644 --- a/apps/solidcraft-web/src/main.rs +++ b/apps/solidcraft-web/src/main.rs @@ -230,13 +230,15 @@ mod web { fn sync_recents(&mut self) { let mut entries = self.files.entries.borrow().clone(); entries.sort_by(|a, b| b.modified.total_cmp(&a.modified)); + let forgotten = self.app.home.forgotten.clone(); let recent = &mut self.app.home.recent; let known = self.files.disk_known.borrow().clone(); // A design on the computer's disk stays listed while its file is remembered. recent.retain(|p| vfs::exists(p) || disk::parse(p).is_some_and(|(id, _)| known.contains(id))); for e in entries.iter().filter(|e| solidcraft_engine::io::is_design_path(&e.name)) { let p = format!("{}{}", files::OPFS, e.name); - if !recent.contains(&p) { + // A design the user removed from the list is not added back while it is stored. + if !recent.contains(&p) && !forgotten.contains(&p) { recent.push(p); } } @@ -245,6 +247,10 @@ mod web { let recovered = self.files.recovery.borrow().as_ref().and_then(|(_, p)| p.clone()); let keep = recent.iter().chain(recovered.as_ref()).filter_map(|p| disk::parse(p)).map(|(id, _)| id.to_string()).collect(); disk::prune(keep); + // Drop forgotten entries whose stored design is gone, so the set does not grow without bound. + let stored: std::collections::BTreeSet = + entries.iter().filter(|e| solidcraft_engine::io::is_design_path(&e.name)).map(|e| format!("{}{}", files::OPFS, e.name)).collect(); + self.app.home.forgotten.retain(|p| stored.contains(p)); } /// The stored designs: open, insert, rename, delete, download; open from the computer. @@ -383,6 +389,8 @@ mod web { "delete" => { files::delete(&self.files, &name); self.app.home.recent.retain(|r| *r != path); + // The file is gone, so there is nothing left to keep forgotten. + self.app.home.forgotten.remove(&path); } "rename_cancel" => self.renaming = None, "rename" => { @@ -396,6 +404,10 @@ mod web { *r = new.clone(); } } + // A forgotten design follows its new name. + if self.app.home.forgotten.remove(&old) { + self.app.home.forgotten.insert(new); + } } Err(e) => self.app.set_status(e, true), } diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index 993d250e5..63782e5fa 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -35,6 +35,10 @@ pub struct HomeState { /// Recent design paths, newest first (kept in the preferences). pub recent: Vec, pub opened_at: std::collections::BTreeMap, + /// Designs the user removed from the list. Kept in the preferences so a host that rebuilds + /// the recent list from its stored designs (the web build, see `sync_recents`) does not add + /// them back. Opening or saving a design clears it from here. + pub forgotten: std::collections::BTreeSet, thumbs: HashMap>, samples: HashMap, /// Keys asked for and not made yet. @@ -94,6 +98,17 @@ impl HomeState { self.opened_at.insert(path.to_string(), web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0)); self.opened_at.retain(|p, _| self.recent.contains(p)); self.thumbs.remove(path); + // Opening or saving a design undoes an earlier removal from the list. + self.forgotten.remove(path); + } + + /// Drop a design from the recent list and remember that the user did so, so a host that + /// rebuilds the list from its stored designs (the web build) does not add it back. + pub fn forget(&mut self, path: &str) { + self.recent.retain(|p| p != path); + self.opened_at.remove(path); + self.thumbs.remove(path); + self.forgotten.insert(path.to_string()); } } @@ -796,8 +811,7 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option