diff --git a/crates/engine/src/cmd/scripts.rs b/crates/engine/src/cmd/scripts.rs index 37a661dfcb..d273dabad5 100644 --- a/crates/engine/src/cmd/scripts.rs +++ b/crates/engine/src/cmd/scripts.rs @@ -95,7 +95,7 @@ pub fn specs() -> Vec { "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 ), diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index b87001e4b5..b8fb0fe84a 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -194,6 +194,7 @@ impl VectorcraftApp { titlebar_inset: 0.0, last_effect: None, last_pathfinder: None, + queued_script_printers: None, last_filters: Default::default(), character_focus: None, run_count: 0, @@ -524,6 +525,7 @@ impl VectorcraftApp { crate::panels::actions::after_journaled_edit(self); crate::scripts_menu::poll(self, ctx); if self.session.script_running() + && !crate::script_runs::waiting_for_print(self) && !self.session.script_waiting() && self.session.script_dialog().is_none() && self.session.script_picker().is_none() diff --git a/crates/ui-egui/src/dialogs/script_run.rs b/crates/ui-egui/src/dialogs/script_run.rs index 22d999782c..ebd7fcb6de 100644 --- a/crates/ui-egui/src/dialogs/script_run.rs +++ b/crates/ui-egui/src/dialogs/script_run.rs @@ -41,8 +41,8 @@ //! are not the dialog's default. `selectDlg` opens the host's folder picker in its own folder. //! //! The jobs a script prepared for a printer (`Document.print` without a file) wait for the dialog of -//! kind `scriptPrint`, which opens once the run has ended and its changes are kept, when no other -//! dialog is open and no text field or text being typed on the canvas has the keyboard. Its fields +//! kind `scriptPrint`, which opens once the run has ended and its changes are kept, when no question +//! or popup is open and no text field or text being typed on the canvas has the keyboard. Its fields //! are `jobs` (each job's `document`, `printer` and `pages`, read from the jobs when it opens; no //! field sets them) and `answer`. Only the person at the keyboard prints them, with a click on its //! Print button or Space once Tab gave it the focus: the button takes no click for @@ -508,6 +508,11 @@ pub(crate) fn asking_to_close(app: &VectorcraftApp) -> bool { with_host(app, |host, _| host.is_open::()).unwrap_or(false) } +/// Whether the question before a script's print jobs are sent is open. +pub(crate) fn asking_to_print(app: &VectorcraftApp) -> bool { + with_host(app, |host, _| host.is_open::()).unwrap_or(false) +} + /// Whether a dialog is open or waits to open: a script's dialog opens only over nothing. pub(crate) fn busy(app: &VectorcraftApp) -> bool { app.any_dialog_open() || with_host(app, |host, _| !host.is_empty()).unwrap_or(false) @@ -991,10 +996,13 @@ fn choose(app: &mut VectorcraftApp) { pub(crate) const PRINT_ENABLE_DELAY_SECS: f64 = 1.0; /// Opens the question before the jobs a script prepared for a printer are sent, once the run has -/// ended, no other dialog is open and nothing is being typed: while a text field or text on the +/// ended, no question or popup is open and nothing is being typed: while a text field or text on the /// canvas has the keyboard it waits, and a later poll opens it. pub(crate) fn ask_print(app: &mut VectorcraftApp) { - if app.session.script_running() || !app.session.script_prints_waiting() || busy(app) { + // Between two queued runs, the jobs the ended run prepared are asked about before the next starts. + let between_runs = app.session.script_name().is_none(); + let blocked = app.asking_dialog_open() || with_host(app, |host, _| !host.is_empty()).unwrap_or(false); + if (app.session.script_running() && !between_runs) || !app.session.script_prints_waiting() || blocked { return; } let typing = app.ui_ctx.as_ref().is_some_and(egui::Context::text_edit_focused) || app.session.tool_wants_text(); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 8a931c60b3..60e133e9f3 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -164,6 +164,9 @@ pub struct VectorcraftApp { pub last_effect: Option<(String, serde_json::Value)>, /// Last successful destructive Pathfinder operation, repeated on the current selection. pub last_pathfinder: Option, + /// The printers listed when `script.startup.run` queued its runs: each queued run lists them + /// as it starts, without asking the print service again. + pub(crate) queued_script_printers: Option, /// The parameters each object filter plug-in last ran with (Object › Plug-ins › Apply Last Filter). pub last_filters: dialogs::plugin::LastFilters, /// The Character panel field that takes the keyboard focus when the panel next draws it diff --git a/crates/ui-egui/src/print.rs b/crates/ui-egui/src/print.rs index 72c984d5cd..d69c73116f 100644 --- a/crates/ui-egui/src/print.rs +++ b/crates/ui-egui/src/print.rs @@ -201,20 +201,29 @@ pub fn script_printers(app: &mut VectorcraftApp) -> Option { Some(Printers::new(service.printers().into_iter().map(|p| (p.name, p.default)), for_printer)) } -/// Runs the engine command `id`. A `script.run` started here lists the printers it may print to -/// ([`script_printers`]), and only that run lists them. +/// 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 { - if id == "script.run" { - app.session.script_printers = script_printers(app); - } + 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; + if id == "script.startup.run" && r.is_ok() { + app.queued_script_printers = listed.filter(|_| app.session.script_running()); + } r } /// 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. @@ -233,8 +242,24 @@ pub(crate) fn send_script_prints(app: &mut VectorcraftApp, jobs: Vec bool { + app.session.script_name().is_none() && (app.session.script_prints_waiting() || script_run::asking_to_print(app)) +} + /// Advances the running script by one slice, or asks what its growth needs asked. pub fn poll(app: &mut VectorcraftApp) { startup_failures(app); @@ -27,10 +32,22 @@ pub fn poll(app: &mut VectorcraftApp) { if app.session.script_name().is_none() && (script_run::asking_to_close(app) || script_run::answer_close_between_runs(app)) { return; } + if waiting_for_print(app) { + return; + } let name = app.session.script_name().unwrap_or_default(); let startup = app.session.startup_script_running(); let shared = share_views(app); + // Between two queued runs, this pump starts the next one: it lists the printers listed when the + // runs were queued. + if app.session.script_name().is_none() { + app.session.script_printers = app.queued_script_printers.clone(); + } let pumped = app.session.script_pump(); + app.session.script_printers = None; + if !app.session.script_running() { + app.queued_script_printers = None; + } take_views(app, &shared); let Some(result) = pumped else { // A pump that started the next queued run shows the runs before it that could not start diff --git a/crates/ui-egui/src/tests/script_print.rs b/crates/ui-egui/src/tests/script_print.rs index 46c6ccc867..327592a654 100644 --- a/crates/ui-egui/src/tests/script_print.rs +++ b/crates/ui-egui/src/tests/script_print.rs @@ -24,10 +24,16 @@ struct Spool { sent: Sent, names: Rc>>, 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>, } impl PrintService for Spool { fn printers(&mut self) -> Vec { + 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 { + 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>>) { 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] @@ -327,6 +443,107 @@ fn a_script_cannot_print_to_a_printer_without_a_service_that_allows_it() { assert!(app.session.script_printers.is_none()); } +/// With startup scripts on, the chosen script starts after them, in a later frame, and still lists +/// the service's printers: its job asks the person as it does without startup scripts. +#[test] +fn a_script_chosen_after_startup_scripts_may_print() { + let (mut app, sent, _) = print_app(true); + 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-{}", 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(); + run(&mut app, PRINT_TO_LAB); + assert!(!app.ui.status.contains("not available here"), "{}", app.ui.status); + assert_eq!(objects(&app), 1, "the chosen script ran"); + assert!(asking(&app), "its job waits for the person"); + assert!(app.session.script_printers.is_none()); + assert!(sent.borrow().is_empty()); + 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> = 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] +fn a_startup_scripts_jobs_are_asked_about_before_the_chosen_script_starts() { + let (mut app, sent, _) = print_app(true); + 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-jobs-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + std::fs::write(dir.join("a.jsx"), "var o = new PrintOptions(); o.printerName = 'Office'; app.activeDocument.print(o);").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": PRINT_TO_LAB, "name": "p.js" })).unwrap().unwrap(); + script_run::with_host(&app, |host, _| host.open(script_run::RunQuestion(craft::ui::dialog::StandardPrompt::custom("Blocked")))).unwrap(); + for _ in 0..10_000 { + script_runs::poll(&mut app); + if app.session.script_prints_waiting() { + break; + } + } + assert!(app.session.script_prints_waiting()); + assert!(!asking(&app), "the print question waits for the other dialog"); + script_runs::poll(&mut app); + assert!(script_runs::waiting_for_print(&app)); + assert!(app.session.script_running() && app.session.script_name().is_none(), "the chosen script waits under another dialog"); + assert_eq!(objects(&app), 0); + script_run::forget::(&app); + let ctx = app.ui_ctx.clone().unwrap(); + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + let _ = craft::ui::dialog::JobProgress::new("Placing", "Reading").show(ui); + }); + out.textures_delta.clear(); + assert!(app.any_dialog_open()); + assert!(!app.asking_dialog_open()); + script_runs::poll(&mut app); + assert!(asking(&app), "the startup script's job is asked about"); + assert!(app.session.script_running() && app.session.script_name().is_none(), "the chosen script waits"); + click_after_delay(&mut app, 10.0, "Print"); + assert_eq!(sent.borrow().iter().map(|(p, ..)| p.clone()).collect::>(), [Some("Office".to_string())]); + for _ in 0..10_000 { + script_runs::poll(&mut app); + if !app.session.script_running() { + break; + } + } + assert!(!app.session.script_running()); + assert_eq!(objects(&app), 1, "the chosen script ran: {}", app.ui.status); + script_runs::poll(&mut app); + assert!(asking(&app), "the chosen script's job is asked about"); + assert!(app.queued_script_printers.is_none()); + let _ = std::fs::remove_dir_all(&dir); +} + /// Space on Print, once Tab gave it the keyboard focus after [`PRINT_ENABLE_DELAY_SECS`], prints: /// a keyboard user can approve the jobs without a mouse. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index bbff1cfdb9..c85072f573 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4523,7 +4523,11 @@ disabled, truncated, unreadable}`, with `then` holding `script.run`'s reply. In reply is `{reason, skipped: false, running, queued, failed, disabled, truncated, unreadable}`, with `failed` naming 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. Stop (`script.stop`) asked for between two runs stops the run that starts next. In the app, stopping the runs from +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; 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, or its error when the chosen script cannot start, and add `startup` holding the `script.startup.run` reply. While a diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 2ac505717a..da0c04d20c 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -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. `crates/engine/tests/script_startup.rs`, `crates/ui-egui/src/tests/scripts_menu.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`.