Show Variables download failures after closing the drawing

This commit is contained in:
dotCooCoo committed 2026-11-26 17:22:01 -08:00
1 parent 3b267aeaa1
commit 06ca78a088
2 files changed
+40 -8

No files matched your search

+12 -4
View File
@@ -40,6 +40,8 @@ pub(crate) enum Owner {
struct Waiting {
ticket: PickId,
owner: Owner,
/// The file service is writing bytes that the caller already prepared.
saving: bool,
/// The active document's uid when asked (`DocState::uid`); `None` for [`Owner::Free`].
doc: Option<u64>,
/// The automation roots in force when asked: the continuation runs under them, not under the
@@ -123,7 +125,7 @@ pub(crate) fn ask(
owner: Owner,
then: impl FnOnce(&mut VectorcraftApp, Picked) -> Result<Value, String> + 'static,
) -> Value {
start(app, owner, |files| files.pick(request), None, then)
start(app, owner, |files| files.pick(request), false, None, then)
}
/// Like [`ask`], but drops a reply if its requester is gone, before choosing a document or reporting a picker error.
@@ -134,7 +136,7 @@ pub(crate) fn ask_while(
current: impl FnOnce(&VectorcraftApp) -> bool + 'static,
then: impl FnOnce(&mut VectorcraftApp, Picked) -> Result<Value, String> + 'static,
) -> Value {
start(app, owner, |files| files.pick(request), Some(Box::new(current)), then)
start(app, owner, |files| files.pick(request), false, Some(Box::new(current)), then)
}
/// Save `bytes` as the file service saves them (`Files::save`: the desktop asks where with `request` and
@@ -147,7 +149,7 @@ pub(crate) fn save(
owner: Owner,
then: impl FnOnce(&mut VectorcraftApp, Picked) -> Result<Value, String> + 'static,
) -> Value {
start(app, owner, |files| files.save(request, bytes), None, then)
start(app, owner, |files| files.save(request, bytes), true, None, then)
}
/// Asks the file service with `ask` and files `then` for its answer.
@@ -155,6 +157,7 @@ fn start(
app: &mut VectorcraftApp,
owner: Owner,
ask: impl FnOnce(&dyn Files) -> PickId,
saving: bool,
current: Option<PickGuard>,
then: impl FnOnce(&mut VectorcraftApp, Picked) -> Result<Value, String> + 'static,
) -> Value {
@@ -165,7 +168,7 @@ fn start(
Owner::Free => None,
};
let (scope, automated) = (ScopeHandle::capture(), app.automation_asked());
app.file_asks.waiting.push(Waiting { ticket, owner, doc, scope, automated, current, then: Box::new(then) });
app.file_asks.waiting.push(Waiting { ticket, owner, saving, doc, scope, automated, current, then: Box::new(then) });
json!({ "pending": "fileDialog" })
}
@@ -309,6 +312,11 @@ pub(crate) fn poll(app: &mut VectorcraftApp) {
}
match &picked {
Picked::Cancelled => continue,
Picked::Failed(error) if w.saving => {
// The file service already had the bytes. It can report a failure without a drawing.
report(app, Err(error.clone()));
continue;
}
Picked::Unavailable(why) => {
// The desktop says what gives it a file dialog; the browser has none for this kind of pick.
#[cfg(not(target_arch = "wasm32"))]
+28 -4
View File
@@ -722,10 +722,7 @@ fn ask_save(app: &mut VectorcraftApp, name: &str, filters: &[(&str, &[&str])], c
return Value::Null;
};
let bytes = text.as_bytes().to_vec();
file_asks::save(app, request, bytes, Owner::Document, move |_app, picked| match picked {
craft::host::Picked::Failed(error) => Err(error),
_ => Ok(Value::Null),
})
file_asks::save(app, request, bytes, Owner::Document, |_, _| Ok(Value::Null))
}
/// Import…: one file dialog for a CSV, TSV, TXT or XML file, and `variable.import` on the chosen
@@ -804,6 +801,33 @@ mod tests {
}
}
#[test]
fn a_failed_variables_download_reports_its_error_after_the_source_closes() {
use craft::host::{Picked, ScriptedFiles};
for command in [EXPORT_DATA_SETS, SAVE_LIBRARY] {
for answer in [Picked::Failed("downloads are blocked".into()), Picked::Cancelled, Picked::Downloaded("export".into())] {
let mut app = app_with_data();
let files = Arc::new(ScriptedFiles::held().in_browser());
crate::tests::picks::install_files(&mut app, files.clone());
run(&mut app, command, &json!({})).unwrap().unwrap();
app.session.execute("file.close", &json!({"index": 0})).unwrap();
app.run("file.new", json!({"width": 80, "height": 80})).unwrap();
app.status("another drawing");
let before = app.session.active().unwrap().doc.clone();
let expected = match &answer {
Picked::Failed(error) => error.as_str(),
Picked::Cancelled => "another drawing",
_ => file_asks::closed(),
};
files.answer(answer.clone());
file_asks::poll(&mut app);
assert_eq!(app.ui.status, expected);
assert_eq!(app.session.active().unwrap().doc, before);
}
}
}
fn app_with_data() -> VectorcraftApp {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 300, "height": 200})).unwrap();