Scripts: startup scripts at launch list no printers, and spool failures stay shown

The startup scripts run at launch no longer list the print service's
printers, so the first window does not wait on it; a script.startup.run
with any other reason still lists them. A script's print jobs that the
desktop's worker fails to send are shown in the status bar even when a
later line, a later batch that was sent or a startup script's failure
took it, and the startup script's notes stay in the hover.
script.startup.run's params text describes the print wait and the
launch rule.
This commit is contained in:
dotCooCoo
2026-12-02 07:39:44 -08:00
parent 096b3b0e24
commit 31d02e4821
5 changed files with 177 additions and 11 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Run Startup Scripts",
[],
None,
"{reason: launch|menu (launch: the app starting; menu: before a script chosen from File › Scripts), then?: script.run's parameters (the script to run once the startup scripts have run; its source is read once and must compile before enabled startup scripts run), maxFuel?: whole number from 1 to 100000000000 (each startup script's instructions; default 1000000000)} run the .jsx files of the Startup Scripts folder next to the settings, one at a time, as script.run runs a file, each with the same limits as any script and its own undo step; nothing runs, and the reply says why, when the runStartupScripts preference is off (the default), in Safe Mode, or in a session without the folder (the web, and a run with VECTORCRAFT_NO_PREFS); only the folder's own .jsx files run, sorted by name without regard to case, then by name; links, hidden files, names starting with a dot, subfolders and other files are left out, and so is a script the Safe Mode choice disabled; a missing folder runs nothing; a script that cannot be read, is larger than 8 MiB, fails or is stopped is named in failed and in the Script Console, and the next one runs, then the script of then; while a startup script runs, the launch marker names it, so a launch that stops there offers to disable it; script.* commands are refused inside a script, so a startup script does not start another startup run. VectorCraft's own rules: the folder, the order, the limits of a listing (2048 folder entries, 512 scripts, 250 ms) and what a failure does → {reason, skipped: true, why: off|safeMode|noFolder, then?: script.run's reply} | {reason, skipped: false, ran: [names], failed: [{name, error}], disabled: [names], truncated, unreadable, then?: script.run's reply}, or, in the app, {reason, skipped: false, running, queued: the runs queued, then's included, failed: [{name, error}] (the runs that could not start before the first one did), disabled, truncated, unreadable, then?: script.run's reply when it ran to its end at once}, each run then reporting as script.run's do, and a later run that cannot start is named in the status bar, where the message of a startup script that fails or is stopped also stays; included files are read again when the chosen run starts; a preflight compilation failure clears the previous script report; each app queue pump processes at most one startup entry",
"{reason: launch|menu (launch: the app starting; menu: before a script chosen from File › Scripts), then?: script.run's parameters (the script to run once the startup scripts have run; its source is read once and must compile before enabled startup scripts run), maxFuel?: whole number from 1 to 100000000000 (each startup script's instructions; default 1000000000)} run the .jsx files of the Startup Scripts folder next to the settings, one at a time, as script.run runs a file, each with the same limits as any script and its own undo step; nothing runs, and the reply says why, when the runStartupScripts preference is off (the default), in Safe Mode, or in a session without the folder (the web, and a run with VECTORCRAFT_NO_PREFS); only the folder's own .jsx files run, sorted by name without regard to case, then by name; links, hidden files, names starting with a dot, subfolders and other files are left out, and so is a script the Safe Mode choice disabled; a missing folder runs nothing; a script that cannot be read, is larger than 8 MiB, fails or is stopped is named in failed and in the Script Console, and the next one runs, then the script of then; while a startup script runs, the launch marker names it, so a launch that stops there offers to disable it; script.* commands are refused inside a script, so a startup script does not start another startup run. VectorCraft's own rules: the folder, the order, the limits of a listing (2048 folder entries, 512 scripts, 250 ms) and what a failure does → {reason, skipped: true, why: off|safeMode|noFolder, then?: script.run's reply} | {reason, skipped: false, ran: [names], failed: [{name, error}], disabled: [names], truncated, unreadable, then?: script.run's reply}, or, in the app, {reason, skipped: false, running, queued: the runs queued, then's included, failed: [{name, error}] (the runs that could not start before the first one did), disabled, truncated, unreadable, then?: script.run's reply when it ran to its end at once}, each run then reporting as script.run's do, and a later run that cannot start is named in the status bar, where the message of a startup script that fails or is stopped also stays; included files are read again when the chosen run starts; a preflight compilation failure clears the previous script report; each app queue pump processes at most one startup entry; in the app, a run lists the printers once when the runs are queued and each queued run may print to them, except with reason launch, whose runs list no printers and cannot print to a printer, and a queued run waits while the jobs the run before it prepared for a printer wait for Print or Cancel",
always,
startup_run
),
+28 -7
View File
@@ -171,12 +171,14 @@ pub fn script_printers(app: &mut VectorcraftApp) -> Option<Printers> {
Some(Printers::new(service.printers().into_iter().map(|p| (p.name, p.default)), for_printer))
}
/// Runs the engine command `id`. A `script.run` or `script.startup.run` started here lists the
/// printers its first run may print to ([`script_printers`]), and only that run lists them; the
/// runs `script.startup.run` queues list the same printers as they start
/// ([`crate::script_runs::poll`]).
/// Runs the engine command `id`. A `script.run`, or a `script.startup.run` whose reason is not
/// `launch`, started here lists the printers its first run may print to ([`script_printers`]), and
/// only that run lists them; the runs `script.startup.run` queues list the same printers as they
/// start ([`crate::script_runs::poll`]). The startup scripts run at launch list no printers, so the
/// first window does not wait on the print service.
pub(crate) fn execute_listing_printers(app: &mut VectorcraftApp, id: &str, params: &Value) -> Result<Value, String> {
let listed = if matches!(id, "script.run" | "script.startup.run") { script_printers(app) } else { None };
let lists = id == "script.run" || (id == "script.startup.run" && params.get("reason").and_then(Value::as_str) != Some("launch"));
let listed = if lists { script_printers(app) } else { None };
app.session.script_printers = listed.clone();
let r = app.session.execute(id, params).map_err(|e| e.to_string());
app.session.script_printers = None;
@@ -189,6 +191,9 @@ pub(crate) fn execute_listing_printers(app: &mut VectorcraftApp, id: &str, param
/// The error for a script's jobs when the print service does not let scripts print.
const NO_SCRIPT_PRINTING: &str = "Printing from scripts is not available here: the script's print jobs were not sent";
/// The start of the status line for a script's print jobs that the desktop's worker failed to send.
const SCRIPT_PRINT_FAILED: &str = "Printing from a script failed";
/// Sends the jobs a script prepared, which the person approved, each to its printer. Every printer
/// must still be one the service lists, by its exact name, or no job is sent. → `{sent}`, or
/// `{background: true}` while the desktop's worker sends them.
@@ -207,8 +212,24 @@ pub(crate) fn send_script_prints(app: &mut VectorcraftApp, jobs: Vec<PreparedPri
None,
move |_| send_each(&mut |job| submit(job), &jobs).map(|notes| json!({ "notes": notes })),
move |app, result| {
let notes = result?;
app.status(notes["notes"].as_array().and_then(|n| n.last()).and_then(Value::as_str).unwrap_or_default());
let notes = result.inspect_err(|e| {
let failure = format!("{SCRIPT_PRINT_FAILED}: {e}");
let mut kept = app
.ui
.status_notes
.take()
.filter(|(status, notes)| *status == app.ui.status || notes.iter().any(|n| n.starts_with(SCRIPT_PRINT_FAILED)))
.map(|(_, notes)| notes)
.unwrap_or_default();
kept.insert(0, failure.clone());
io::show_with_notes(app, failure, kept);
})?;
let failed = app.ui.status_notes.clone().filter(|(_, notes)| notes.iter().any(|n| n.starts_with(SCRIPT_PRINT_FAILED)));
if let Some((status, kept)) = failed {
io::show_with_notes(app, status, kept);
} else if !app.ui.status.starts_with(SCRIPT_PRINT_FAILED) {
app.status(notes["notes"].as_array().and_then(|n| n.last()).and_then(Value::as_str).unwrap_or_default());
}
Ok(json!({ "sent": count }))
},
);
+144 -1
View File
@@ -24,10 +24,16 @@ struct Spool {
sent: Sent,
names: Rc<RefCell<Vec<String>>>,
scripts: bool,
/// When set, jobs go to the desktop's worker, which fails to spool them with this message, or
/// sends them when it is empty.
spool_error: Option<&'static str>,
/// How many times the printers were listed.
lists: Rc<std::cell::Cell<usize>>,
}
impl PrintService for Spool {
fn printers(&mut self) -> Vec<Printer> {
self.lists.set(self.lists.get() + 1);
self.names.borrow().iter().enumerate().map(|(i, name)| Printer::new(name.clone()).is_default(i == 0)).collect()
}
@@ -39,6 +45,11 @@ impl PrintService for Spool {
fn scripts_may_print(&self) -> bool {
self.scripts
}
fn shared_print(&self) -> Option<crate::print::SharedPrintFn> {
let error = self.spool_error?;
Some(std::sync::Arc::new(move |_| if error.is_empty() { Ok("Sent".to_string()) } else { Err(error.to_string()) }))
}
}
/// An app in a window, with a document, a print service listing Office (the default) and Lab, and
@@ -46,7 +57,7 @@ impl PrintService for Spool {
fn print_app(scripts: bool) -> (VectorcraftApp, Sent, Rc<RefCell<Vec<String>>>) {
let sent = Sent::default();
let names = Rc::new(RefCell::new(vec!["Office".to_string(), "Lab".to_string()]));
let spool = Spool { sent: sent.clone(), names: names.clone(), scripts };
let spool = Spool { sent: sent.clone(), names: names.clone(), scripts, spool_error: None, lists: Default::default() };
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services { print: Some(Box::new(spool)), ..Default::default() }));
app.run("file.new", json!({})).unwrap();
app.session.prefs.show_external_script_warning = false;
@@ -303,6 +314,111 @@ fn a_failed_run_or_a_printer_that_went_away_sends_nothing() {
assert!(!asking(&app));
}
/// An app whose script print jobs go to the desktop's worker, which fails with `error` (or sends
/// them when it is empty).
fn worker_print_app(error: &'static str) -> VectorcraftApp {
let spool = Spool {
sent: Sent::default(),
names: Rc::new(RefCell::new(vec!["Office".to_string(), "Lab".to_string()])),
scripts: true,
spool_error: Some(error),
lists: Default::default(),
};
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services { print: Some(Box::new(spool)), ..Default::default() }));
app.services.write_shared = Some(std::sync::Arc::new(|_, _| Ok(())));
app.run("file.new", json!({})).unwrap();
app.session.prefs.show_external_script_warning = false;
app
}
/// A job the desktop's worker fails to spool is reported even when another line, such as the next
/// queued script's, took the status bar while the worker ran.
#[test]
fn a_spool_failure_shows_after_a_later_status_line() {
let mut app = worker_print_app("The printer Lab is offline");
run(&mut app, PRINT_TO_LAB);
assert!(asking(&app));
click_after_delay(&mut app, 10.0, "Print");
app.status("The next script ran");
crate::background::wait_all(&mut app);
assert!(app.ui.status.contains("The printer Lab is offline"), "{}", app.ui.status);
}
/// A later batch the worker sent does not replace an earlier batch's failure in the status bar.
#[test]
fn a_sent_batch_does_not_hide_an_earlier_spool_failure() {
let mut app = worker_print_app("");
run(&mut app, PRINT_TO_LAB);
assert!(asking(&app));
click_after_delay(&mut app, 10.0, "Print");
app.status("Printing from a script failed: The printer Office is offline");
crate::background::wait_all(&mut app);
assert!(app.ui.status.contains("The printer Office is offline"), "{}", app.ui.status);
}
/// A spool failure stays visible after the next batch is approved and sent.
#[test]
fn a_batch_submitted_after_a_spool_failure_does_not_hide_it() {
let mut app = worker_print_app("The printer Lab is offline");
run(&mut app, PRINT_TO_LAB);
click_after_delay(&mut app, 10.0, "Print");
run(&mut app, PRINT_TO_LAB);
assert!(asking(&app));
crate::background::wait_all(&mut app);
let failure = app.ui.status.clone();
assert!(failure.contains("The printer Lab is offline"), "{failure}");
assert!(asking(&app));
app.services.print = worker_print_app("").services.print;
click_after_delay(&mut app, 20.0, "Print");
assert!(!asking(&app));
assert!(!app.background.jobs.is_empty(), "the next batch was submitted");
assert_eq!(app.ui.status, "Printing from a script…");
crate::background::wait_all(&mut app);
assert_eq!(app.ui.status, failure);
assert_eq!(app.ui.status_notes, Some((failure.clone(), vec![failure])));
}
/// A spool failure keeps the startup scripts' errors in the status bar's hover notes.
#[test]
fn a_spool_failure_does_not_hide_a_later_startup_script_failure() {
let mut app = worker_print_app("The printer Lab is offline");
app.session.set_script_listing_clock(vectorcraft_engine::script::folder::Clock::Fixed(std::time::Duration::ZERO));
let dir = std::env::temp_dir().join(format!("vc-script-print-startup-failure-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("a.jsx"), PRINT_TO_LAB).unwrap();
std::fs::write(dir.join("b.jsx"), "throw new Error('The later startup script failed');").unwrap();
app.session.attach_startup_scripts_dir(dir.clone());
app.run("prefs.set", json!({"key": "runStartupScripts", "value": true})).unwrap();
menus::run_ui_command(&mut app, "ui.runScript", &json!({ "source": "vc.log(1);", "name": "chosen" })).unwrap().unwrap();
for _ in 0..10_000 {
script_runs::poll(&mut app);
if asking(&app) {
break;
}
}
assert!(asking(&app));
click_after_delay(&mut app, 10.0, "Print");
for _ in 0..10_000 {
script_runs::poll(&mut app);
if !app.session.script_running() {
break;
}
}
assert!(!app.session.script_running());
assert!(app.ui.startup_notes.is_empty(), "the startup round ended");
assert!(app.ui.status.contains("The later startup script failed"), "{}", app.ui.status);
let startup_notes = app.ui.status_notes.as_ref().unwrap().1.clone();
crate::background::wait_all(&mut app);
assert!(app.ui.status.contains("The printer Lab is offline"), "{}", app.ui.status);
let (status, notes) = app.ui.status_notes.as_ref().unwrap();
assert_eq!(status, &app.ui.status, "the hover notes match the displayed status");
assert!(notes.len() > 1, "the hover lists both failures");
assert!(notes.contains(status));
assert!(startup_notes.iter().all(|note| notes.contains(note)), "{notes:?}");
let _ = std::fs::remove_dir_all(&dir);
}
/// Without a service that lets scripts print (the web's), or without any, printing to a printer
/// from a script throws and nothing is asked or sent.
#[test]
@@ -348,6 +464,33 @@ fn a_script_chosen_after_startup_scripts_may_print() {
let _ = std::fs::remove_dir_all(&dir);
}
/// The startup scripts run at launch do not list the printers, so the first window does not wait
/// on the print service.
#[test]
fn the_startup_scripts_at_launch_list_no_printers() {
let lists: Rc<std::cell::Cell<usize>> = Default::default();
let spool = Spool {
sent: Sent::default(),
names: Rc::new(RefCell::new(vec!["Office".to_string()])),
scripts: true,
spool_error: None,
lists: lists.clone(),
};
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services { print: Some(Box::new(spool)), ..Default::default() }));
app.session.set_script_listing_clock(vectorcraft_engine::script::folder::Clock::Fixed(std::time::Duration::ZERO));
let dir = std::env::temp_dir().join(format!("vc-script-print-launch-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("a.jsx"), "vc.log(1);").unwrap();
app.session.attach_startup_scripts_dir(dir.clone());
app.run("prefs.set", json!({"key": "runStartupScripts", "value": true})).unwrap();
script_runs::run_at_launch(&mut app);
assert!(app.session.script_running(), "the startup script started: {}", app.ui.status);
assert_eq!(lists.get(), 0, "the printers were not listed");
assert!(app.queued_script_printers.is_none());
let _ = std::fs::remove_dir_all(&dir);
}
/// A startup script's jobs are asked about before the chosen script starts, so that script may
/// print too.
#[test]
+3 -1
View File
@@ -4524,7 +4524,9 @@ reply is `{reason, skipped: false, running, queued, failed, disabled, truncated,
the runs that could not start before the first one did. Each run then reports as a `script.run` in the app does, the
next one starts at the frame after, and a later run that cannot start, the chosen script included, is named in the
status bar. A queued run also waits while the jobs the previous run prepared for a printer wait for Print or Cancel.
Each queued run lists the printers listed when the runs were queued.
Each queued run lists the printers listed when the runs were queued; the runs with reason `launch` list no
printers, so they cannot print to a printer. A job that fails to spool is reported in the status bar even when a
later run or a later job's note took it.
Stop (`script.stop`) asked for between two runs stops the run that starts next. In the app, stopping the runs from
the prompt shown on quitting, between two runs, drops the runs not yet started, and the status bar says so. While that prompt is open, the next run does not start. Under `--automation-read-root` it reads the folder only when the folder lies inside a
read root. With the preference on, `ui.runScript` and `ui.runInstalledScript` still return `script.run`'s reply,
+1 -1
View File
@@ -1155,7 +1155,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Scripts: `new ExternalObject("lib:AdobeXMPScript")` gives `XMPMeta`, `XMPFile` and `XMPConst` ([the help page](https://extendscript.docsforadobe.dev/scripting-xmp/xmpscript-object-reference/)): properties, arrays, language alternatives and namespaces read from a packet, changed and serialized, and a `.xmp` sidecar read and written with `getXMP`, `putXMP` and `closeFile`. VectorCraft's own rules: `XMPFile` reads and writes only where `File` may; other files are scanned for their packet and read only; a packet over 8 MiB or not well-formed throws; members not built yet (iterators, structure fields, qualifiers, aliases) throw that they are not available yet. `crates/js/src/xmp_tests.rs`, `crates/engine/src/tests/script_xmp.rs`.
- Scripts: `#strict on` (and `//@strict on`) runs the script with the checks the [`$` object](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/) help page gives for `$.strict`: an assignment to a read-only property throws a `TypeError`, and so does a new property on an object that takes none. VectorCraft's own rules: a getter-only property counts as read-only, the objects that take no new properties are the non-extensible ones (`Object.preventExtensions`, `seal`, `freeze`, and the frozen `vc` and `$` objects), the last `#strict` line of the script and its includes sets the whole run, a file `$.evalFile` runs keeps its own line's checks for its code, and the rest of ES5 strict mode stays with `'use strict'`. Without the line, runs are unchanged. `crates/engine/src/tests/script_include.rs` (`strict_on_*`, `strict_mode_in_eval_file_is_scoped`), `crates/js/src/interp_tests.rs` (`strict_writes_are_separate_from_es5_strict`).
- Scripts folder: File › Scripts lists the `.js` and `.jsx` files of the `Scripts` folder next to the preferences, each named after its file without the extension, with each subfolder as a submenu, above Check Script… and Other Script… (https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/install-and-run-scripts.html). VectorCraft's own rules: the folder is read again when the window becomes active and when the File menu opens (in the macOS menu bar, when any of its menus opens, and the new listing shows the next time the menu opens), links are not followed, and one read stops at 2,048 entries, 512 scripts, 128 subfolders, 4 levels or 250 ms. `script.listInstalled` returns the listing. `crates/engine/src/tests/script_folder.rs`, `crates/ui-egui/src/tests/scripts_menu.rs`.
- Startup scripts: with Preferences › General › Run Startup Scripts on, the `.jsx` files of the `Startup Scripts` folder next to the preferences run when VectorCraft starts and before each script chosen from File › Scripts ([the scripting guide](https://web.archive.org/web/20210515232518/https://www.adobe.com/content/dam/acom/en/devnet/illustrator/pdf/Illustrator_Scripting_Guide_cc.pdf), page 11). VectorCraft's own rules: the preference is off by default; only the folder's own `.jsx` files run, sorted by name without regard to case, each with the limits of any script and its own undo step; one that fails is named in the Script Console and the next one runs, then the chosen script; nothing runs in Safe Mode, the launch marker names the running startup script so a launch that stops there offers to disable it, and a startup script cannot start another round. `script.startup.run` runs the folder. A queued run also waits while the jobs the previous run prepared for a printer wait for Print or Cancel, and each queued run lists the printers listed when the runs were queued. `crates/engine/tests/script_startup.rs`, `crates/ui-egui/src/tests/scripts_menu.rs`, `crates/ui-egui/src/tests/script_print.rs`, `crates/ui-egui/tests/safe_mode.rs`.
- Startup scripts: with Preferences › General › Run Startup Scripts on, the `.jsx` files of the `Startup Scripts` folder next to the preferences run when VectorCraft starts and before each script chosen from File › Scripts ([the scripting guide](https://web.archive.org/web/20210515232518/https://www.adobe.com/content/dam/acom/en/devnet/illustrator/pdf/Illustrator_Scripting_Guide_cc.pdf), page 11). VectorCraft's own rules: the preference is off by default; only the folder's own `.jsx` files run, sorted by name without regard to case, each with the limits of any script and its own undo step; one that fails is named in the Script Console and the next one runs, then the chosen script; nothing runs in Safe Mode, the launch marker names the running startup script so a launch that stops there offers to disable it, and a startup script cannot start another round. `script.startup.run` runs the folder. A queued run also waits while the jobs the previous run prepared for a printer wait for Print or Cancel, and each queued run lists the printers listed when the runs were queued; the startup scripts run at launch list no printers. `crates/engine/tests/script_startup.rs`, `crates/ui-egui/src/tests/scripts_menu.rs`, `crates/ui-egui/src/tests/script_print.rs`, `crates/ui-egui/tests/safe_mode.rs`.
- Messages over the window: `app.toast {message, level?, seconds?}` shows a message at the window's bottom right that does not stop work and closes after its time (4 seconds by default) or when clicked; at most 5 show at once, the newest lowest. Scripts raise one through `vc.run`, MCP clients through the command, and an action records it as a step. The limits are VectorCraft's own values. Tests: `cmd::toast::tests` in `vectorcraft-engine`, `toasts::tests` in `vectorcraft-ui-egui`.
- Plug-in run notices: a filter or plug-in command's output may report a `notice`, which needs no permission; once the output is applied, `plugin.run` and the command return it and the status bar shows it as `Plug-in “name”: notice`, escaped, cut at 200 characters and never translated, and a run that fails or is refused shows none. VectorCraft's own API and limits. Tests: `objects::tests::notice_is_escaped_capped_and_checked` in `vectorcraft-plugins`, `a_filter_s_notice_is_returned_once_its_output_is_applied` and `a_plugin_command_returns_its_run_s_notice` in `vectorcraft-engine`, `plugin_notice_shows_after_the_plug_in_s_name_and_is_never_translated` in `vectorcraft-ui-egui`.
- Open Recent Files under `--automation-read-root`: the control channel's `ui.menu.list` and `file.recentFiles` leave out the recent files outside the read roots, the other rows keep their ids, and `file.openRecentN` for one outside them answers `no such recent file`, as an empty slot does. `crates/ui-egui/src/tests/automation.rs`.