EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge main and preserve Startup script tasks across project changes
dotCooCoo5e32a2a39cd3
diff --cc crates/engine/src/cmd/scripts.rsindex 396c1c474,d352e636c..3131bed60--- a/crates/engine/src/cmd/scripts.rs+++ b/crates/engine/src/cmd/scripts.rs@@@ -323,73 -308,7 +323,86 @@@ fn restore_panels(s: &mut Session, _: &Ok(json!({"opened": opened, "failed": failed}))}+/// Run the scripts in `dir` of the settings store one after another, in alphabetical order (case+/// ignored), as After Effects runs its Startup and Shutdown folders. A script that fails is+/// reported in a toast and the log and listed in `failed`; the next one still runs. A script waiting in a+/// modal dialog is listed in `waiting` and goes on when the dialog closes; the next one runs+/// meanwhile. With `quitting`, no window is left to show a dialog in, so each dialog closes as+/// if canceled (`show()` returns 2) and the script runs on.+fn run_folder(s: &mut Session, dir: &str, quitting: bool) -> Value {+ let mut names: Vec<String> = s.config.as_ref().map(|c| c.list(dir)).unwrap_or_default().into_iter().filter(|n| is_script(n) && is_script_name(n)).collect();+ names.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()).then_with(|| a.cmp(b)));+ let (mut ran, mut waiting, mut failed) = (vec![], vec![], vec![]);+ for name in names {+ let code = match s.config.as_ref().map(|c| c.read_bounded(&format!("{dir}/{name}"), MAX_SCRIPT_BYTES)) {+ Some(Ok(Some(code))) => code,+ read => {+ let why = match read {+ Some(Err(e)) => format!(": {e}"),+ _ => String::new(),+ };+ let error = format!("{name}: cannot read the script{why}");+ log::warn!("{dir}: {error}");+ s.events.push(Event::Toast { message: error.clone(), error: true });+ failed.push(json!({"name": name, "error": error}));+ continue;+ }+ };+ let is_waiting = |r: &Result<Value>| r.as_ref().is_ok_and(|v| v.get("waiting").and_then(Value::as_bool) == Some(true));+ // In a settings folder on disk, the script runs as its file, so `#include`, `$.fileName`+ // and `$.evalFile` find the files beside it.+ let path = s.config.as_ref().and_then(|c| c.dir()).map(|d| d.join(dir).join(&name).to_string_lossy().into_owned()).unwrap_or_else(|| name.clone());+ // Windows open before this script runs belong to other scripts, perhaps of the same name.+ let before: Vec<u32> = s.script_ui.windows.iter().map(|w| w.id).collect();++ let hosts_before = s.script_ui.task_hosts.clone();+ let mut r = super::file_more::run_js_file(s, &code, &path, &name);++ if !quitting {++ // The Startup script's context: the one that scheduled tasks or holds the windows it++ // opened (a task scheduled after its dialog closes runs there too).++ let tasks = s.script_ui.task_hosts.iter().filter(|h| !hosts_before.contains(h)).copied();++ let windows = s.script_ui.windows.iter().filter(|w| !before.contains(&w.id)).map(|w| w.host);++ let hosts: Vec<u32> = tasks.chain(windows).collect();++ for h in hosts {++ if !s.script_ui.startup_hosts.contains(&h) {++ s.script_ui.startup_hosts.push(h);++ }++ }++ }+ let mut closed = 0;+ while quitting && closed < MAX_SHUTDOWN_DIALOGS && is_waiting(&r) {+ let Some(id) = s.script_ui.windows.iter().rev().find(|w| w.modal && w.script == path && !before.contains(&w.id)).map(|w| w.id) else { break };+ // report_js reports an error the script throws after its dialog closes, as it does for an+ // error in the script's first run.+ r = scriptui::close(s, &json!({"window": id})).and_then(|out| super::file_more::report_js(s, &name, out));+ closed += 1;+ }+ match r {+ Ok(_) if is_waiting(&r) => waiting.push(name),+ Ok(_) => ran.push(name),+ Err(e) => {+ // Also in the log: no frame draws a Shutdown script's toast.+ log::warn!("{dir}: {e}");+ failed.push(json!({"name": name, "error": e.to_string()}));+ }+ }+ }+ json!({"ran": ran, "waiting": waiting, "failed": failed})+}++/// `file.runStartupScripts`: run the scripts in `Scripts/Startup` (frontends call it once at+/// launch, before a project opens).+fn run_startup(s: &mut Session, _: &Value) -> Result<Value> {+ Ok(run_folder(s, STARTUP_DIR, false))+}++/// `file.runShutdownScripts`: close the project, then run the scripts in `Scripts/Shutdown`+/// (frontends call it as the app quits, after the unsaved-changes prompt).+fn run_shutdown(s: &mut Session, _: &Value) -> Result<Value> {+ s.replace_project(effectcraft_project::Project::default(), None);+ Ok(run_folder(s, SHUTDOWN_DIR, true))+}+- /// Window ▸ <ScriptUI panel>: run the panel script (or bring its panel forward).+ /// Window ▸ `<ScriptUI panel>`: run the panel script (or bring its panel forward).fn open_panel(s: &mut Session, p: &Value) -> Result<Value> {let c = "window.scriptPanel";let name = str_p(p, "name").ok_or_else(|| bad(c, "missing `name` (a script in the ScriptUI Panels folder)"))?.to_string();diff --cc crates/engine/src/scriptui.rsindex 6d218a7bb,6d218a7bb..082f0c861--- a/crates/engine/src/scriptui.rs+++ b/crates/engine/src/scriptui.rs@@@ -402,12 -402,12 +402,16 @@@ pub struct ScriptUi#[serde(skip)]pub tasks: Option<ScriptTaskRunner>,/// Bumped whenever the project is closed or replaced (New / Open / Close Project): repeating-- /// tasks of scripts without an open window stop then.++ /// tasks of scripts without an open window stop then, except those of Startup scripts.#[serde(skip)]pub project_epoch: u64,/// The script contexts of this session with scheduled tasks (kept by the scripting engine).#[serde(skip)]pub task_hosts: Vec<u32>,++ /// The script contexts of Startup scripts: their tasks go on when the project is closed or++ /// replaced, until EffectCraft quits.++ #[serde(skip)]++ pub startup_hosts: Vec<u32>,}impl ScriptUi {diff --cc crates/script/src/lib.rsindex 8472881d9,11d837677..f4694acfa--- a/crates/script/src/lib.rs+++ b/crates/script/src/lib.rs@@@ -88,30 -88,7 +88,9 @@@ pub fn run_code(s: &mut Session, code:#[cfg(test)]mod tests;+#[cfg(test)]- mod tests_callable;- #[cfg(test)]- mod tests_ease_presets;- #[cfg(test)]- mod tests_include;- #[cfg(test)]- mod tests_panels;- #[cfg(test)]+mod tests_startup;- #[cfg(test)]- mod tests_tasks;- #[cfg(test)]- mod tests_ui;- #[cfg(test)]- mod tests_ui_more;// #760: `$.evalFile` and `BridgeTalk`.- #[cfg(test)]- mod tests_evalfile;// `/browser/…` is the web editor's file table, an absolute path on wasm; on Windows it has no// drive, so the script runtime resolves it under the current drive, where the host holds nothing.- #[cfg(test)]- #[cfg(not(windows))]- mod tests_services;- #[cfg(test)]- mod tests_ui_mouse;diff --cc crates/script/src/tests_startup.rsindex 6c13aaf30,000000000..67da833c5mode 100644,000000..100644--- a/crates/script/src/tests_startup.rs+++ b/crates/script/src/tests_startup.rs@@@ -1,269 -1,0 +1,290 @@@+//! Startup and Shutdown scripts, as in After Effects: the scripts in the user's `Scripts/Startup`+//! and `Scripts/Shutdown` folders (in the settings folder) run in alphabetical order at launch and+//! as the app quits, after the project is closed.++use std::sync::Arc;++use effectcraft_engine::Session;+use effectcraft_engine::commands::scripts::{OPEN_PANELS_FILE, PANELS_DIR, SCRIPTS_DIR, SHUTDOWN_DIR, STARTUP_DIR};+use effectcraft_engine::config::{ConfigStore, MemoryConfig};+use effectcraft_engine::scriptui::WindowKind;+use serde_json::json;++fn session(store: &Arc<MemoryConfig>) -> Session {+ let mut s = Session::default();+ crate::install(&mut s);+ s.config = Some(store.clone());+ s+}++/// A script that appends `mark` to the `Startup Test` / `order` script setting.+fn mark(mark: &str) -> String {+ format!(+ r#"var k = app.settings.haveSetting("Startup Test", "order") ? app.settings.getSetting("Startup Test", "order") : "";+app.settings.saveSetting("Startup Test", "order", k + "{mark}");"#+ )+}++fn setting(s: &mut Session, key: &str) -> serde_json::Value {+ s.execute("script.settings.get", json!({"section": "Startup Test", "key": key})).unwrap()["value"].clone()+}++#[test]+fn startup_scripts_run_in_alphabetical_order_and_a_failing_one_does_not_stop_the_rest() {+ let store = Arc::new(MemoryConfig::default());+ store.write(&format!("{STARTUP_DIR}/b.jsx"), &mark("b")).unwrap();+ store.write(&format!("{STARTUP_DIR}/A.jsx"), &mark("A")).unwrap();+ store.write(&format!("{STARTUP_DIR}/B2.jsx"), &mark("B")).unwrap();+ store.write(&format!("{STARTUP_DIR}/C.js"), "throw new Error('no');").unwrap();+ store.write(&format!("{STARTUP_DIR}/d.jsx"), &mark("d")).unwrap();+ // Not scripts, or not in the Startup folder: not run.+ store.write(&format!("{STARTUP_DIR}/notes.txt"), &mark("x")).unwrap();+ store.write(&format!("{SCRIPTS_DIR}/Menu Script.jsx"), &mark("m")).unwrap();+ store.write(&format!("{SHUTDOWN_DIR}/Quit.jsx"), &mark("q")).unwrap();+ let mut s = session(&store);+ let r = s.execute("file.runStartupScripts", json!({})).unwrap();+ assert_eq!(r["ran"], json!(["A.jsx", "b.jsx", "B2.jsx", "d.jsx"]), "{r}");+ let failed: Vec<&str> = r["failed"].as_array().unwrap().iter().map(|f| f["name"].as_str().unwrap()).collect();+ assert_eq!(failed, ["C.js"]);+ assert_eq!(setting(&mut s, "order"), "AbBd");+ // The failing script is reported in a toast.+ let events = s.drain_events();+ assert!(events.iter().any(|e| matches!(e, effectcraft_engine::Event::Toast { message, error: true } if message.starts_with("C.js"))), "{events:?}");+ // The Startup folder's scripts are not offered in File ▸ Scripts.+ let list = s.execute("file.scripts.list", json!({})).unwrap();+ assert!(list.as_array().unwrap().iter().all(|e| e["name"] != "b.jsx"), "{list}");+}++#[test]+fn shutdown_scripts_run_after_the_project_is_closed() {+ let store = Arc::new(MemoryConfig::default());+ let probe = r#"app.settings.saveSetting("Startup Test", "items", String(app.project.numItems));"#;+ store.write(&format!("{SHUTDOWN_DIR}/Save State.jsx"), probe).unwrap();+ let mut s = session(&store);+ s.execute("script.run", json!({"code": r#"app.project.items.addComp("Main", 64, 64, 1, 1, 24);"#})).unwrap();+ assert!(!s.project.items.is_empty());+ let r = s.execute("file.runShutdownScripts", json!({})).unwrap();+ assert_eq!(r, json!({"ran": ["Save State.jsx"], "waiting": [], "failed": []}));+ assert_eq!(setting(&mut s, "items"), "0");+ assert!(s.project.items.is_empty());+}++#[test]+fn a_startup_dialog_stays_open_and_its_script_goes_on_when_it_closes() {+ let store = Arc::new(MemoryConfig::default());+ store.write(&format!("{STARTUP_DIR}/A Dialog.jsx"), &format!("new Window('dialog', 'Welcome').show();\n{}", mark("A"))).unwrap();+ store.write(&format!("{STARTUP_DIR}/B.jsx"), &mark("B")).unwrap();+ let mut s = session(&store);+ let r = s.execute("file.runStartupScripts", json!({})).unwrap();+ assert_eq!(r, json!({"ran": ["B.jsx"], "waiting": ["A Dialog.jsx"], "failed": []}));+ assert_eq!(setting(&mut s, "order"), "B");+ assert!(s.script_ui.windows.iter().any(|w| w.modal && w.title == "Welcome"));+ s.execute("scriptui.close", json!({})).unwrap();+ assert_eq!(setting(&mut s, "order"), "BA");+}+++#[test]++fn startup_scripts_tasks_go_on_after_a_project_opens() {++ use web_time::{Duration, Instant};++ let store = Arc::new(MemoryConfig::default());++ store.write(&format!("{STARTUP_DIR}/A Poll.jsx"), "app.scheduleTask('writeLn(\"poll\")', 100, true);").unwrap();++ // A task scheduled after the script's dialog closes.++ store.write(&format!("{STARTUP_DIR}/B Ask.jsx"), "new Window('dialog', 'Ask').show();\napp.scheduleTask('writeLn(\"ask\")', 100, true);").unwrap();++ let mut s = session(&store);++ s.execute("file.runStartupScripts", json!({})).unwrap();++ s.execute("scriptui.close", json!({})).unwrap();++ // The launch opens a project after the Startup scripts ran.++ s.execute("file.closeProject", json!({})).unwrap();++ let r = crate::tasks::run_tasks_at(&mut s, Instant::now() + Duration::from_millis(500));++ assert_eq!(r["ran"], json!(2), "{r}");++ // A script run from File ▸ Scripts still stops when the project closes.++ s.execute("script.run", json!({"code": "app.scheduleTask('writeLn(\"menu\")', 100, true);", "name": "Menu.jsx"})).unwrap();++ s.execute("file.closeProject", json!({})).unwrap();++ let r = crate::tasks::run_tasks_at(&mut s, Instant::now() + Duration::from_millis(5000));++ assert_eq!(r["ran"], json!(2), "{r}");++}+++#[test]+fn shutdown_dialogs_close_as_if_canceled() {+ let store = Arc::new(MemoryConfig::default());+ let code = r#"var a = new Window("dialog", "One").show();+var b = new Window("dialog", "Two").show();+app.settings.saveSetting("Startup Test", "shown", a + "," + b);"#;+ store.write(&format!("{SHUTDOWN_DIR}/Ask.jsx"), code).unwrap();+ // An error after the dialog closes is a failure.+ store.write(&format!("{SHUTDOWN_DIR}/Broken.jsx"), "new Window('dialog', 'Three').show();\nthrow new Error('late');").unwrap();+ let mut s = session(&store);+ let r = s.execute("file.runShutdownScripts", json!({})).unwrap();+ assert_eq!((&r["ran"], &r["waiting"]), (&json!(["Ask.jsx"]), &json!([])), "{r}");+ assert_eq!(r["failed"][0]["name"], "Broken.jsx", "{r}");+ assert!(r["failed"][0]["error"].as_str().is_some_and(|e| e.contains("late")), "{r}");+ assert_eq!(setting(&mut s, "shown"), "2,2");+ assert!(s.script_ui.windows.is_empty());+}++#[test]+fn shutdown_closes_only_its_own_scripts_dialogs() {+ let store = Arc::new(MemoryConfig::default());+ store.write(&format!("{STARTUP_DIR}/Same.jsx"), &format!("new Window('dialog', 'Startup').show();\n{}", mark("S"))).unwrap();+ store.write(&format!("{SHUTDOWN_DIR}/Same.jsx"), &format!("new Window('dialog', 'Shutdown').show();\n{}", mark("Q"))).unwrap();+ let mut s = session(&store);+ assert_eq!(s.execute("file.runStartupScripts", json!({})).unwrap()["waiting"], json!(["Same.jsx"]));+ let r = s.execute("file.runShutdownScripts", json!({})).unwrap();+ assert_eq!(r, json!({"ran": ["Same.jsx"], "waiting": [], "failed": []}));+ // The Startup script's dialog is still open, and its script has not gone on.+ assert_eq!(setting(&mut s, "order"), "Q");+ let titles: Vec<&str> = s.script_ui.windows.iter().map(|w| w.title.as_str()).collect();+ assert_eq!(titles, ["Startup"]);+}++#[test]+fn oversized_scripts_are_not_run() {+ let store = Arc::new(MemoryConfig::default());+ let big = format!("{}\n{}", "//".repeat(8 << 20), mark("x"));+ store.write(&format!("{STARTUP_DIR}/Big.jsx"), &big).unwrap();+ let mut s = session(&store);+ let r = s.execute("file.runStartupScripts", json!({})).unwrap();+ assert_eq!(r["ran"], json!([]));+ assert_eq!(r["failed"][0]["name"], "Big.jsx");+ let events = s.drain_events();+ assert!(events.iter().any(|e| matches!(e, effectcraft_engine::Event::Toast { message, error: true } if message.starts_with("Big.jsx"))), "{events:?}");+ assert_eq!(setting(&mut s, "order"), "");+}++#[test]+fn scripts_in_a_settings_folder_on_disk_include_files_beside_them() {+ use effectcraft_engine::config::DirConfig;+ let root = std::env::temp_dir().join(format!("ec-startup-include-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&root);+ for (file, code) in [+ (format!("{STARTUP_DIR}/lib/helper.jsx"), mark("i")),+ (format!("{STARTUP_DIR}/Main.jsx"), format!("#include \"lib/helper.jsx\"\n{}", mark("m"))),+ (format!("{SHUTDOWN_DIR}/Ask.jsx"), format!("new Window('dialog', 'Bye').show();\n{}", mark("q"))),+ ] {+ let path = root.join(file);+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();+ std::fs::write(path, code).unwrap();+ }+ let mut s = Session::default();+ crate::install(&mut s);+ s.config = Some(Arc::new(DirConfig::new(&root)));+ let r = s.execute("file.runStartupScripts", json!({})).unwrap();+ assert_eq!(r, json!({"ran": ["Main.jsx"], "waiting": [], "failed": []}));+ assert_eq!(setting(&mut s, "order"), "im");+ // A Shutdown script run as its file still has its dialog closed.+ let r = s.execute("file.runShutdownScripts", json!({})).unwrap();+ assert_eq!(r, json!({"ran": ["Ask.jsx"], "waiting": [], "failed": []}));+ assert_eq!(setting(&mut s, "order"), "imq");+ let _ = std::fs::remove_dir_all(&root);+}++/// A session with one comp, for checking that a refused command leaves the project open.+fn session_with_comp(store: &Arc<MemoryConfig>) -> Session {+ let mut s = session(store);+ s.execute("script.run", json!({"code": r#"app.project.items.addComp("Main", 64, 64, 1, 1, 24);"#})).unwrap();+ assert!(!s.project.items.is_empty());+ s+}++const FOLDER_COMMANDS: [&str; 2] = ["file.runStartupScripts", "file.runShutdownScripts"];++#[test]+fn scripts_cannot_run_the_startup_or_shutdown_folders() {+ let store = Arc::new(MemoryConfig::default());+ for id in FOLDER_COMMANDS {+ let mut s = session_with_comp(&store);+ let r = s.execute("script.run", json!({"code": format!("app.run('{id}', {{}})")})).unwrap();+ assert!(r["error"]["message"].as_str().is_some_and(|m| m.contains("scripts can't run scripts")), "{id}: {r}");+ assert!(!s.project.items.is_empty(), "{id}");+ }+}++#[test]+fn command_scripts_cannot_run_the_startup_or_shutdown_folders() {+ let store = Arc::new(MemoryConfig::default());+ for id in FOLDER_COMMANDS {+ let mut s = session_with_comp(&store);+ let e = s.execute("file.runScript", json!({"steps": [{"command": id}]})).unwrap_err().to_string();+ assert!(e.contains("scripts can't run scripts"), "{id}: {e}");+ assert!(!s.project.items.is_empty(), "{id}");+ }+}++#[test]+fn batches_cannot_run_the_startup_or_shutdown_folders() {+ let store = Arc::new(MemoryConfig::default());+ for id in FOLDER_COMMANDS {+ let mut s = session_with_comp(&store);+ let e = s.execute("engine.batch", json!({"steps": [{"command": id}]})).unwrap_err().to_string();+ assert!(e.contains("can't run inside a batch"), "{id}: {e}");+ assert!(!s.project.items.is_empty(), "{id}");+ }+}++/// A ScriptUI panel whose script appends `p` to the `Startup Test` / `order` setting each time it+/// runs, remembered as open at the last quit.+fn session_with_panel(store: &Arc<MemoryConfig>) -> Session {+ store.write(&format!("{PANELS_DIR}/Mark Panel.jsx"), &format!("this.add('statictext', undefined, 'Mark');\n{}", mark("p"))).unwrap();+ store.write(OPEN_PANELS_FILE, &json!({"open": ["Mark Panel.jsx"]}).to_string()).unwrap();+ session(store)+}++fn panel_open(s: &Session) -> bool {+ s.script_ui.windows.iter().any(|w| w.kind == WindowKind::Panel && w.script == "Mark Panel.jsx")+}++/// The commands that open ScriptUI panels, which run the panel's script.+fn panel_commands() -> [(&'static str, serde_json::Value); 2] {+ [("window.scriptPanel", json!({"name": "Mark Panel.jsx"})), ("window.restoreScriptPanels", json!({}))]+}++#[test]+fn scripts_cannot_open_script_panels() {+ for (id, params) in panel_commands() {+ let store = Arc::new(MemoryConfig::default());+ let mut s = session_with_panel(&store);+ // Opened by the user: a script's call would only bring it forward.+ s.execute("window.scriptPanel", json!({"name": "Mark Panel.jsx"})).unwrap();+ let r = s.execute("script.run", json!({"code": format!("app.run('{id}', {params})")})).unwrap();+ assert!(r["error"]["message"].as_str().is_some_and(|m| m.contains("scripts can't run scripts")), "{id}: {r}");+ assert_eq!(setting(&mut s, "order"), "p", "{id}");+ assert_eq!(store.read(OPEN_PANELS_FILE).unwrap_or_default(), json!({"open": ["Mark Panel.jsx"]}).to_string(), "{id}");+ }+}++#[test]+fn command_scripts_and_batches_cannot_open_script_panels() {+ for (id, params) in panel_commands() {+ let store = Arc::new(MemoryConfig::default());+ let mut s = session_with_panel(&store);+ let e = s.execute("file.runScript", json!({"steps": [{"command": id, "params": params}]})).unwrap_err().to_string();+ assert!(e.contains("scripts can't run scripts"), "{id}: {e}");+ let e = s.execute("engine.batch", json!({"steps": [{"command": id, "params": params}]})).unwrap_err().to_string();+ assert!(e.contains("can't run inside a batch"), "{id}: {e}");+ assert!(!panel_open(&s), "{id}");+ assert_eq!(setting(&mut s, "order"), "", "{id}");+ }+}++#[test]+fn the_app_still_reopens_script_panels_at_launch() {+ let store = Arc::new(MemoryConfig::default());+ let mut s = session_with_panel(&store);+ // As the desktop and web apps call it at launch.+ let r = s.execute("window.restoreScriptPanels", json!({})).unwrap();+ assert_eq!(r, json!({"opened": ["Mark Panel.jsx"], "failed": []}));+ assert!(panel_open(&s));+ assert_eq!(setting(&mut s, "order"), "p");+}++#[test]+fn empty_or_missing_folders_run_nothing() {+ let none = json!({"ran": [], "waiting": [], "failed": []});+ let store = Arc::new(MemoryConfig::default());+ let mut s = session(&store);+ assert_eq!(s.execute("file.runStartupScripts", json!({})).unwrap(), none);+ // A session without a settings folder.+ let mut s = Session::default();+ crate::install(&mut s);+ assert_eq!(s.execute("file.runShutdownScripts", json!({})).unwrap(), none);+}diff --cc crates/script/src/ui.rsindex 082a16cac,082a16cac..ab6f69846--- a/crates/script/src/ui.rs+++ b/crates/script/src/ui.rs@@@ -404,8 -404,8 +404,14 @@@ fn dispatch_inline(session: &mut Sessio// ---------------------------------------------------------------- scheduled tasks++/// Whether `host`'s tasks stop now that the project it ran with was closed: it has no window++/// open and is not a Startup script's.++fn ends_with_project(session: &Session, host: u32) -> bool {++ !session.script_ui.windows.iter().any(|w| w.host == host) && !session.script_ui.startup_hosts.contains(&host)++}++/// Run the due tasks of the script-host threads; hosts without windows whose project was closed--/// end.++/// end, except Startup scripts' hosts.#[cfg(not(target_arch = "wasm32"))]pub(crate) fn tick_threaded(session: &mut Session, now: Instant, report: &mut crate::tasks::Report) {let epoch = session.script_ui.project_epoch;@@@ -413,8 -413,8 +419,7 @@@if let Ok(mut h) = hosts().lock() {for host in session.script_ui.task_hosts.clone() {let Some(end) = h.get(&host) else { continue };-- let windowless = !session.script_ui.windows.iter().any(|w| w.host == host);-- if windowless && end.epoch != epoch {++ if end.epoch != epoch && ends_with_project(session, host) {// Dropping its end lets the host thread finish.stale.extend(h.remove(&host));} else if end.next_due.is_some_and(|d| d <= now) {@@@ -441,7 -441,7 +446,7 @@@}/// Run the due tasks of the inline hosts on this thread (the Script Console, web runs); those--/// without windows whose project was closed stop.++/// without windows whose project was closed stop, except Startup scripts' hosts.pub(crate) fn tick_inline(session: &mut Session, now: Instant, report: &mut crate::tasks::Report) {for (host, name, epoch) in crate::tasks::hosts() {if !session.script_ui.task_hosts.contains(&host) {@@@ -449,7 -449,7 +454,7 @@@}let windowless = !session.script_ui.windows.iter().any(|w| w.host == host);let alive = host == CONSOLE_HOST || INLINE.with(|m| m.borrow().contains_key(&host));-- if !alive || (windowless && epoch != session.script_ui.project_epoch) {++ if !alive || (epoch != session.script_ui.project_epoch && ends_with_project(session, host)) {crate::tasks::drop_host(host);if host != CONSOLE_HOST && windowless {drop_inline(host);diff --cc docs/scripting-parity.mdindex 55bd4a212,7ef7e9080..ddaeec724--- a/docs/scripting-parity.md+++ b/docs/scripting-parity.md@@@ -21,9 -21,9 +21,9 @@@ our own scripts; no real-world script l| Scripting object model | `app`, `Project`, items, layers, properties, keys, eases, render queue, `TextDocument`, `Shape`, markers, `File`/`Folder`, `Socket`, `app.settings` | Same classes, edits run through undoable engine commands; match names table; layers, groups and properties are callable (`layer("Effects")(1)` is `.property(...)`) | good | `crates/script` tests (≈ 10 test files) || `$.evalFile`, `BridgeTalk` | Evaluate another script file; identify the host application and message other Adobe applications | `$.evalFile` evaluates a file relative to the calling file (nested at most 32 deep, under the scripts' file gate) and returns its last value; `BridgeTalk` names the host honestly (`appName` `effectcraft`, its version); messaging other applications throws "not supported" | partial | `tests_evalfile.rs` (#760); no inter-application messaging || ScriptUI | Dialogs, palettes, dockable panels, resource strings, `onDraw` / ScriptUIGraphics, mouse events | Same, dockable panels reopen at launch | good | `ui_scriptui`, `tests_ui*` |--| `app.scheduleTask` / `cancelTask` | One-shot and repeating tasks (polling, panel refresh) until `cancelTask` | Same: repeating tasks run every `delay` ms (at least 50 ms, at most 64 pending per script) until `cancelTask`, until they throw (reported once, then cancelled), or until their owner goes: a script's last window closing, or the project closing for scripts without windows; frontends tick them every frame, agents with `script.runTasks` | good | `tests_tasks.rs` (#773); one-shot tasks of a script file still run right after it, not after their delay |++| `app.scheduleTask` / `cancelTask` | One-shot and repeating tasks (polling, panel refresh) until `cancelTask` | Same: repeating tasks run every `delay` ms (at least 50 ms, at most 64 pending per script) until `cancelTask`, until they throw (reported once, then cancelled), or until their owner goes: a script's last window closing, or the project closing for scripts without windows (a Startup script's tasks go on until EffectCraft quits); frontends tick them every frame, agents with `script.runTasks` | good | `tests_tasks.rs` (#773); one-shot tasks of a script file still run right after it, not after their delay || Scripts menu, ScriptUI Panels folder | yes | yes | same | [plugins.md](plugins.md) |-| Startup / Shutdown folders | yes | not run | missing | plugins.md |+| Startup / Shutdown folders | yes | `Scripts/Startup` runs at launch and `Scripts/Shutdown` runs as the desktop app quits, after the project is closed, each in alphabetical order | partial | `tests_startup.rs`; each script has its own global scope, so a Startup script's variables and functions are not available to later scripts ([plugins.md](plugins.md)) || `#include`, `#target` directives | yes | `#include` / `//@include` / `#includepath` inline files relative to the including script (once each, nested at most 32 deep, under the scripts' file gate; errors name the included file and line); `#target`, `#targetengine`, `#strict` are ignored | good | `tests_include.rs` (#759); installed scripts and panels have no folder of their own, so they include from the project's folder or absolute paths || `.jsxbin` | yes | no | out of scope | No public specification || Keyboard shortcuts for scripts | yes | no | missing | plugins.md |