mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-04 19:42:12 -05:00
Keep host copy saves from marking the open document saved
(cherry picked from commit 2624b9b9d2)
This commit is contained in:
@@ -179,8 +179,8 @@ fn app_canvas() -> Option<web_sys::HtmlCanvasElement> {
|
||||
/// says `file: false` and a host sends `bytes`.
|
||||
/// - `pdfcraft:open` (from the host): `{ name, bytes }` holding a PDF. It opens in a tab, like a
|
||||
/// `?file=` URL; a file over [`host::MAX_OPEN_BYTES`] is refused before it is copied.
|
||||
/// - `pdfcraft:save` (to the host): `{ name, saveAs, bytes }` when the user saves, posted by the
|
||||
/// browser file service. The host stores the file (and reports its own errors).
|
||||
/// - `pdfcraft:save` (to the host): `{ name, saveAs, bytes }` when the user saves through the
|
||||
/// connected bridge. The host stores the file and reports its own errors.
|
||||
/// - `pdfcraft:dirty` whenever unsaved work appears or goes away, `pdfcraft:failed` when the app
|
||||
/// couldn't start.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
||||
@@ -266,8 +266,9 @@ impl PdfCraftApp {
|
||||
pub(super) fn save_to_host(&mut self, ctx: &egui::Context, id: DocId, name: &str, target: SaveTarget) -> Option<bool> {
|
||||
self.host_save.as_ref()?;
|
||||
let Some((_, bytes)) = self.document_bytes(ctx, id, target, None) else { return Some(false) };
|
||||
let result = self.host_save.as_ref()?(name, &bytes, target == SaveTarget::As);
|
||||
let result = self.host_save.as_ref()?(name, &bytes, target != SaveTarget::InPlace);
|
||||
match result {
|
||||
Ok(()) if target == SaveTarget::Copy => Some(true),
|
||||
Ok(()) => Some(self.finish_save(ctx, id, bytes, None)),
|
||||
Err(e) => {
|
||||
self.notify_fmt("Couldn't save {name}: {e}", &[("name", name), ("e", &e)]);
|
||||
|
||||
@@ -98,9 +98,12 @@ fn host_save_delivers_pathless_document_and_preserves_failures() {
|
||||
assert!(!app.session.get(id).unwrap().dirty);
|
||||
assert!(app.session.get(id).unwrap().path.is_none(), "host delivery does not create a filesystem path");
|
||||
assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::As), Some(true));
|
||||
app.apply_edit(&ctx, pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 });
|
||||
assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::Copy), Some(true));
|
||||
assert!(app.session.get(id).unwrap().dirty, "saving a copy does not mark the original saved");
|
||||
let saved = received.lock().unwrap();
|
||||
assert_eq!(saved.len(), 2);
|
||||
assert_eq!((&saved[0].0, saved[0].2, saved[1].2), (&"sample.pdf".to_string(), false, true));
|
||||
assert_eq!(saved.len(), 3);
|
||||
assert_eq!((saved[0].0.as_str(), saved[0].2, saved[1].2, saved[2].2), ("sample.pdf", false, true, true));
|
||||
let mut reopened = pdfcraft_engine::Session::new();
|
||||
let opened = reopened.open("saved.pdf", None, saved[0].1.clone(), None).unwrap();
|
||||
assert_eq!(reopened.get(opened).unwrap().info.pages[0].rotation, 90);
|
||||
|
||||
Reference in New Issue
Block a user