Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,8 @@ impl Session {
self.state
}

/// The project as it is now is saved (written to its file, or downloaded in the browser).
/// The project as it is now is saved: written to its file. A browser download doesn't
/// count, as the page can't tell whether the browser saved it.
pub fn mark_saved(&mut self) {
self.saved = Some(self.state);
}
Expand Down
25 changes: 17 additions & 8 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,9 @@ impl RustGisApp {
}

/// Downloads the project as `file` (web), naming the project after it as Save As does
/// natively. A name without the `.rgis` extension gets it.
/// natively. A name without the `.rgis` extension gets it. Existing unsaved changes stay
/// unsaved, and a rename makes a clean project unsaved: the browser doesn't say whether
/// it wrote the file (the save prompt can be cancelled, the download blocked).
pub(crate) fn save_download(&mut self, file: &str) -> Result<(), String> {
let file = file.trim();
let stem = if file.to_ascii_lowercase().ends_with(".rgis") { file.get(..file.len() - 5).unwrap_or(file) } else { file }.trim();
Expand All @@ -1750,7 +1752,7 @@ impl RustGisApp {
}
let stem: String = stem.chars().take(200).collect();
// Not an undoable edit: saving names the project, as `project.saveAs` does, once the
// file is written.
// browser takes the file.
Comment on lines 1754 to +1755

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quality nit (comment timing). The comment says the name is set "once the browser takes the file", but the name is changed before the download call and only restored if the download fails. The code is right; the comment describes the wrong order. Small fix:

Suggested change
// Not an undoable edit: saving names the project, as `project.saveAs` does, once the
// file is written.
// browser takes the file.
// Not an undoable edit: saving names the project, as `project.saveAs` does. The name stays
// set while the download is offered, and goes back if the download fails.

Confidence: high (about 90%). Quality point, so it can wait for the release quality pass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation sets the name before offering the download and restores it on failure. This comment-timing correction is left for the release quality pass; no behavior change is needed.

let old = std::mem::replace(&mut self.session.project.name, stem.clone());
let (text, report) = match self.session.project.saved_text(None) {
Ok(saved) => saved,
Expand All @@ -1764,17 +1766,24 @@ impl RustGisApp {
self.session.project.name = old;
return Err(e);
}
self.session.notify(crate::i18n::fmt("Downloaded {name}", &[("name", &file)]), false);
if self.session.project.name != old {
Comment thread
Mavrick-F marked this conversation as resolved.
Resolved
// Save As changed the document even when it began clean. Offering a download
// cannot confirm that this renamed document reached a file.
self.session.mark_unsaved();
}
self.session.notify(
crate::i18n::fmt("Download offered: {name}. The browser doesn't say whether it saved the file.", &[("name", &file)]),
false,
);
for notice in report.notices() {
self.session.notify(notice, false);
}
self.session.mark_saved();
self.ui.web_file = Some(file);
Ok(())
}

/// Offers bytes as a download (web), and says whether it was delivered (a failure is
/// notified).
/// Offers bytes as a download (web), and says whether the browser accepted the offer.
/// A failure is notified; acceptance does not confirm that a file was saved.
pub(crate) fn download_bytes(&mut self, name: &str, bytes: Vec<u8>) -> bool {
self.download(name, bytes)
}
Expand All @@ -1787,7 +1796,7 @@ impl RustGisApp {
self.session.notify(e, true);
return false;
}
self.session.notify(crate::i18n::fmt("Downloaded {name}", &[("name", name)]), false);
self.session.notify(crate::i18n::fmt("Download offered: {name}", &[("name", name)]), false);
true
}
None => false,
Expand Down Expand Up @@ -6616,7 +6625,7 @@ mod download_service_tests {
assert!(app.save_download("renamed.rgis").is_err());
assert_eq!(app.session.project.name, name);
assert_eq!(app.ui.web_file, saved_name);
assert!(!app.session.notices.iter().any(|n| n.text.contains("Downloaded")));
assert!(!app.session.notices.iter().any(|n| n.text.contains("Download offered")));
assert!(!app.download("archive.pmtiles", vec![1, 2, 3]));
assert!(app.session.notices.iter().any(|n| n.error && n.text.contains("browser rejected download")));
assert!(!app.session.notices.iter().any(|n| n.text.contains("Downloaded")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quality (test cannot fail). This test still checks for "Downloaded", a notice this PR no longer produces, so the assertion always passes. It was meant to check that a refused download() announces no success. Checking the new text fixes it:

Suggested change
assert!(!app.session.notices.iter().any(|n| n.text.contains("Downloaded")));
assert!(!app.session.notices.iter().any(|n| n.text.contains("Download offered")));

Confidence: high (about 95%). Quality point; a dead assertion in a test the PR touched, so it's worth fixing in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass: update the remaining rejected-download assertion to use the new success wording. The failure path already returns before any success notice.

Expand Down
15 changes: 12 additions & 3 deletions crates/ui-egui/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2987,6 +2987,8 @@ fn connections_tree_browses_and_adds() {

/// Save in the web app (issue #197): the browser has no save dialog, so the first Save and every
/// Save As ask for the file name, and Save then downloads under it; an opened file keeps its name.
/// A download offered isn't a file saved (the user can cancel the browser's prompt), so the
/// project keeps its unsaved changes and leaving the page still warns.
#[test]
fn web_save_asks_for_the_file_name() {
let got = std::sync::Arc::new(std::sync::Mutex::new(Vec::<(String, Vec<u8>)>::new()));
Expand All @@ -3008,8 +3010,10 @@ fn web_save_asks_for_the_file_name() {
app,
);
let names = |got: &std::sync::Mutex<Vec<(String, Vec<u8>)>>| got.lock().unwrap().iter().map(|(n, _)| n.clone()).collect::<Vec<_>>();
// A project never saved: Save asks first, with the project's name.
h.state_mut().run("layer.color", json!({"layer": "Countries", "color": "#336699"})).unwrap();
// A clean document's Save As rename is itself unsaved; no unrelated dirty edit is needed
// to keep the browser's close warning active after a download is merely offered.
h.state_mut().session.mark_saved();
assert!(!h.state().session.dirty());
h.state_mut().run("ui.save", json!(null)).unwrap();
assert_eq!(h.state().dialogs.open, Some("saveProject"));
assert_eq!(h.state().dialogs.text, "World Atlas.rgis");
Comment thread
Mavrick-F marked this conversation as resolved.
Resolved
Expand All @@ -3029,7 +3033,8 @@ fn web_save_asks_for_the_file_name() {
assert_eq!(h.state().dialogs.open, None);
assert_eq!(names(&got), ["Trip plan.rgis"]);
assert_eq!(h.state().session.project.name, "Trip plan");
assert!(!h.state().session.dirty());
assert!(h.state().session.dirty(), "a download offered doesn't mark the project saved");
assert!(h.state().session.notices.iter().any(|n| n.text.starts_with("Download offered: Trip plan.rgis")));
// Saved once: Save downloads under that name again without asking; Save As asks.
h.state_mut().run("ui.save", json!(null)).unwrap();
assert_eq!(h.state().dialogs.open, None);
Expand All @@ -3042,9 +3047,13 @@ fn web_save_asks_for_the_file_name() {
let bytes = got.lock().unwrap()[0].1.clone();
h.state_mut().open_picked("test.rgis", &bytes).unwrap();
assert_eq!(h.state().session.project.name, "test");
assert!(!h.state().session.dirty());
h.state_mut().run("ui.save", json!(null)).unwrap();
assert_eq!(h.state().dialogs.open, None);
assert_eq!(names(&got).last().map(String::as_str), Some("test.rgis"));
assert!(!h.state().session.dirty(), "an unchanged opened project stays clean after a download offer");
let notice = h.state().session.notices.iter().rev().find(|n| n.text.starts_with("Download offered: test.rgis")).unwrap();
assert!(!notice.text.contains("unsaved changes"), "{}", notice.text);
// Another project in its place hasn't been saved: Save asks again, even under the same name.
let n = names(&got).len();
h.state_mut().run("project.new", json!({"name": "test"})).unwrap();
Expand Down
5 changes: 4 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ RustGIS also runs in the browser, compiled to WebAssembly: open
- **Save** and **Export** download the file. **Save As**, and the first **Save** of a project,
ask for the file name first; the browser decides which folder downloads go to (Firefox, for
one, saves to its Downloads folder unless told to ask). A project opened from a file is named
after it, and **Save** downloads it under that name again.
after it, and **Save** downloads it under that name again. The browser doesn't tell RustGIS
whether it saved a download (its save prompt can be cancelled), so **Save** keeps any unsaved
changes, and **Save As** to a different name makes the project unsaved. Closing or leaving
the tab asks first while there are unsaved changes; an unchanged project stays clean.
Comment thread
Mavrick-F marked this conversation as resolved.
Resolved
- The interface uses the built-in font, because a web page can't read installed fonts. Choosing
Chinese, Japanese, Korean or Persian downloads a font for that script.
- Process plugins (including Python plugins), and the formats read through GDAL or DuckDB,
Expand Down
Loading