Scripts: show startup scripts that cannot start when a launch or chosen run begins

script.startup.run returns the startup scripts that could not start before the first run did, such as a file larger than 8 MiB, in its reply's failed list. The launch and the File > Scripts runs now show each one in the status bar as name: error, so a launch where every startup script fails to start no longer shows nothing.
This commit is contained in:
dotCooCoo committed 2026-11-22 06:15:57 -08:00
1 parent c85f3ebb5a
commit 3a00d4a73a
2 files changed
+64 -4

No files matched your search

+20 -4
View File
@@ -89,12 +89,24 @@ fn ask(app: &mut VectorcraftApp) -> bool {
}
/// Runs the script of `params` (`script.run`'s) that the person chose from File › Scripts, after
/// the startup scripts when General › Run Startup Scripts is on (`script.startup.run`).
/// the startup scripts when General › Run Startup Scripts is on (`script.startup.run`). A startup
/// script that cannot start shows in the status bar.
pub(crate) fn run_chosen(app: &mut VectorcraftApp, params: Value) -> Result<Value, String> {
if app.session.startup_skip().is_some() {
return app.run("script.run", params);
}
app.run("script.startup.run", json!({"reason": "menu", "then": params}))
let reply = app.run("script.startup.run", json!({"reason": "menu", "then": params}))?;
reply_failures(app, &reply);
Ok(reply)
}
/// Shows each startup script that a `script.startup.run` reply names under `failed`: the queued
/// runs that could not start before the first one did.
fn reply_failures(app: &mut VectorcraftApp, reply: &Value) {
for failed in reply["failed"].as_array().into_iter().flatten() {
let (name, error) = (failed["name"].as_str().unwrap_or_default(), failed["error"].as_str().unwrap_or_default());
app.status(format!("{name}: {error}"));
}
}
/// When the app has started, out of Safe Mode: the startup scripts run when General › Run Startup
@@ -105,8 +117,12 @@ pub fn run_at_launch(app: &mut VectorcraftApp) {
return;
}
match app.run("script.startup.run", json!({"reason": "launch"})) {
Ok(reply) if reply["unreadable"] == true => app.status("The Startup Scripts folder cannot be read"),
Ok(_) => {}
Ok(reply) => {
reply_failures(app, &reply);
if reply["unreadable"] == true {
app.status("The Startup Scripts folder cannot be read");
}
}
Err(e) => app.status(e),
}
}
+44
View File
@@ -643,6 +643,50 @@ fn a_last_startup_script_that_cannot_start_shows_in_the_status_bar_when_the_runs
let _ = std::fs::remove_dir_all(dir);
}
/// `dir`'s `Startup Scripts` folder, attached to `app`, holding only `0.jsx`, too large to run.
fn oversized_startup_folder(app: &mut VectorcraftApp, dir: &std::path::Path) {
let startup = dir.join("Startup Scripts");
std::fs::create_dir_all(&startup).unwrap();
let mut big = "//".to_string();
big.push_str(&"x".repeat(vectorcraft_engine::script::MAX_SOURCE_BYTES));
std::fs::write(startup.join("0.jsx"), big).unwrap();
app.session.attach_startup_scripts_dir(startup);
}
#[test]
fn a_launch_whose_only_startup_script_cannot_start_shows_it_in_the_status_bar() {
let dir = folder("startup-launch-too-large");
let mut app = app(&dir);
oversized_startup_folder(&mut app, &dir);
app.run("prefs.set", json!({"key": "runStartupScripts", "value": true})).unwrap();
app.status("before");
script_runs::run_at_launch(&mut app);
let shown = format!("0.jsx: {}", vectorcraft_engine::cmd::scripts::TOO_LARGE);
assert_eq!(app.ui.status, shown);
assert!(!app.session.script_running());
script_runs::poll(&mut app);
assert_eq!(app.ui.status, shown);
assert_eq!(objects(&app), 0);
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_menu_run_after_a_first_startup_script_that_cannot_start_shows_it_and_runs_the_chosen_script() {
let dir = folder("startup-menu-too-large");
let mut app = app(&dir);
oversized_startup_folder(&mut app, &dir);
app.session.prefs.show_external_script_warning = false;
app.run("prefs.set", json!({"key": "runStartupScripts", "value": true})).unwrap();
app.status("before");
menus::run_ui_command(&mut app, "ui.runScript", &json!({ "source": DRAW, "name": "chosen" })).unwrap().unwrap();
assert_eq!(app.ui.status, format!("0.jsx: {}", vectorcraft_engine::cmd::scripts::TOO_LARGE));
finish(&mut app);
assert_eq!(started(&app), ["0.jsx", "chosen"]);
assert_eq!(objects(&app), 2);
assert_eq!(app.ui.status, "Ran chosen");
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn with_run_startup_scripts_on_other_script_with_a_missing_file_fails_before_the_startup_scripts() {
let dir = folder("startup-missing");