forked from 1b-agent/opencadstudio-upstream
feat(wasm): web Save/Save As go through the dialog with a direct download
On the web, Save and Save As now open the in-app Save dialog (filename + format) like the desktop, and the unsaved-changes prompt's Save routes through it too — instead of an immediate rfd download. Confirm serializes to bytes and downloads directly via a Blob + hidden `<a download>` click (a user gesture), so there is no intermediate "click to download" link. Replaces the rfd-based download_web / WebSaveResult round-trip with a synchronous sys::download_bytes. Native save is unchanged. Native + web build; 75 tests pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
93d136c5db
commit
fefae274d4
6 files changed
+99
-107
No files matched your search
@@ -372,18 +372,6 @@ pub fn save_to_bytes(doc: &CadDocument, ext: &str) -> Result<Vec<u8>, String> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Web "save as": offer a download of `bytes` under `name` via the browser's
|
||||
/// save dialog. Returns the file name on success.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub async fn download_web(name: String, bytes: Vec<u8>) -> Result<String, String> {
|
||||
let handle = rfd::AsyncFileDialog::new()
|
||||
.set_file_name(&name)
|
||||
.save_file()
|
||||
.await
|
||||
.ok_or_else(|| "Cancelled".to_string())?;
|
||||
handle.write(&bytes).await.map_err(|e| e.to_string())?;
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
// ── Post-load fixups ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in new issue
Block a user