Repository navigation
fix(ui): keep browser downloads unsaved #1696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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(); | ||||||
|
|
@@ -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. | ||||||
| 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, | ||||||
|
|
@@ -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 { | ||||||
|
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) | ||||||
| } | ||||||
|
|
@@ -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, | ||||||
|
|
@@ -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"))); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quality (test cannot fail). This test still checks for
Suggested change
Confidence: high (about 95%). Quality point; a dead assertion in a test the PR touched, so it's worth fixing in this PR.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
|
|
||||||
There was a problem hiding this comment.
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:
Confidence: high (about 90%). Quality point, so it can wait for the release quality pass.
There was a problem hiding this comment.
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.