G2: web Save As asks before replacing a stored project (#2788)

This commit is contained in:
Jonas Neubauer
2026-11-02 01:15:08 +01:00
parent 55a8a7e0d9
commit bfe7535a5e
+10 -3
View File
@@ -215,14 +215,21 @@ fn install_hooks(app: &mut EffectcraftApp) {
}));
// Saving downloads the file: the chosen name is all a "save dialog" needs. A project (Save As,
// Save a Copy) asks for the name, starting from the open project's (#2788): without asking,
// Save As would replace the open project's file; Cancel cancels.
// Save As would replace the open project's file; Cancel cancels. A name that is already in
// browser storage asks before replacing it, as the desktop's save dialogs do.
app.hooks.pick_save = Some(Box::new(|name: &str| {
let name = if name.is_empty() { "Untitled Project.ecproj" } else { name };
if !std::path::Path::new(name).extension().is_some_and(|e| e.eq_ignore_ascii_case("ecproj") || e.eq_ignore_ascii_case("ecprojx")) {
return Some(files::path_for(name));
}
let typed = web_sys::window().and_then(|w| w.prompt_with_message_and_default("Save project as:", name).ok().flatten());
crate::store::typed_save_name(name, typed).map(|n| files::path_for(&n))
let window = web_sys::window()?;
let typed = window.prompt_with_message_and_default("Save project as:", name).ok().flatten();
let typed = crate::store::typed_save_name(name, typed)?;
let path = files::path_for(&typed);
if files::get(&path).is_some() && !window.confirm_with_message(&format!("{typed} already exists. Replace it?")).unwrap_or(false) {
return None;
}
Some(path)
}));
app.hooks.audio_device = Some(Box::new(audio::open));
app.hooks.audio_devices = Some(Box::new(|| vec!["Browser default output".into()]));