From 6e7cc34c9e4d2996ec020480de56afa0175e8909 Mon Sep 17 00:00:00 2001 From: onlykshitij <30444410+onlykshitij@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:45:29 +0530 Subject: [PATCH] Scripts: window.scriptPanel opens only ScriptUI panels It fell back to any script, so a script outside the ScriptUI Panels folder opened as a panel and was remembered, then reported missing and forgotten at the next launch (restore looks only for panels). Review feedback from CodeRabbit on #2289. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/commands/scripts.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/commands/scripts.rs b/crates/engine/src/commands/scripts.rs index 726c20c2d..9ad5fc88e 100644 --- a/crates/engine/src/commands/scripts.rs +++ b/crates/engine/src/commands/scripts.rs @@ -341,7 +341,8 @@ fn open_panel(s: &mut Session, p: &Value) -> Result { s.events.push(Event::Frontend { command: c.into(), params: json!({"window": id}) }); return Ok(json!({"window": id, "open": true})); } - let (_, code) = script_code(s, &name, Some(true)).or_else(|| script_code(s, &name, None)).ok_or_else(|| bad(c, format!("no ScriptUI panel `{name}`")))?; + // Only panels: a script opened as one would be remembered, then forgotten at the next launch. + let (_, code) = script_code(s, &name, Some(true)).ok_or_else(|| bad(c, format!("no ScriptUI panel `{name}`")))?; let out = super::file_more::run_js_named(s, &panel_wrapper(&title, &code), &name)?; let id = s.script_ui.windows.iter().rev().find(|w| w.kind == scriptui::WindowKind::Panel && w.script == name).map(|w| w.id); if let Some(id) = id { @@ -601,6 +602,10 @@ mod tests { let ran = r["result"]["ran"].as_str().unwrap_or_default(); assert!(ran.contains("animate") && ran.contains(r#"__uiDockPanel("Animate")"#), "{r}"); assert_eq!(script_code(&s, "Motion Kit/Animate.jsx", Some(true)), Some((true, "animate".to_string()))); + // A script that is not a panel doesn't open as one. + for name in ["Tools/Hello.jsx", "Rename Layers.jsx"] { + assert!(bad_params(&s.execute("window.scriptPanel", json!({"name": name}))), "{name}"); + } for name in ["../x.jsx", "a/b/c.jsx", "a\\b.jsx", "Motion Kit/sub/Deep.jsx", "ScriptUI Panels/Top.jsx", "Tools/../../../outside.jsx"] { assert_eq!(script_code(&s, name, None), None, "{name:?}"); for c in ["file.runScript", "window.scriptPanel", "file.uninstallScript"] {