Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
#163: a Mac app made by `raea app bundle` runs its page host as the launcher's child instead of exec'ing it. The launcher (Contents/MacOS/NAME, a sh script) ended with `exec raea-page-host`, and when the process LaunchServices launched execs another program, AppKit keeps the app's bundle id but loses its pid: NSRunningApplication's processIdentifier is -1, so window managers that find an app's windows by its pid (AeroSpace) never see the window. Measured on macOS 27.0.1 with a windowless AppKit program opened through LaunchServices: exec from sh or bash gives -1; the program as the bundle's executable, or as the child of a sh or bash launcher that waits, gives its own pid. The launcher now starts the host in the background, passes TERM, INT and HUP on to it and waits for it, ending with its status; the host still checks in as the app, since it lives inside it. Its test (macapp.rs) runs the launcher on a stand-in host that writes down its pid and its parent's: on the old launcher it fails (the host's pid was the launcher's), on the new one the host is the launcher's child, on the app's files, and the launcher ends with the host's status. engine/page/window native.rs said the exec is what gives raea.app's window its identity; it is the program's place in Contents/MacOS, and raea.app's launcher now starts its window as a child too.
shinyobjectz09c2df6e8c6f
diff --git a/apps/targets/src/macapp.rs b/apps/targets/src/macapp.rsindex 6dc0962a..011e58b8 100644--- a/apps/targets/src/macapp.rs+++ b/apps/targets/src/macapp.rs@@ -1,6 +1,7 @@//! `raea app bundle` on the web target: a Mac app that opens the page in raea-page-host's window. App.app/Contents has//! the page host, the app's script and stylesheet in Resources/, and a launcher in MacOS/ that starts the host on them-//! at the app's title and size, signed by the developer (sign.rs, T1d).+//! at the app's title and size, signed by the developer (sign.rs, T1d). The launcher runs the host as its child and+//! waits for it: a launcher that execs it leaves the app without a pid in AppKit (#163, `launcher`).use std::path::PathBuf;@@ -37,6 +38,20 @@ fn sh(s: &str) -> String {format!("'{}'", s.replace('\'', "'\\''"))}+/// The app's executable (Contents/MacOS/NAME): the page host in Resources, on the app's script and stylesheet, in a+/// window at the app's title and size. The host is this script's child, never exec'd in its place: when the process+/// macOS launched execs another program, AppKit keeps the app's bundle id but loses its pid (NSRunningApplication's+/// processIdentifier -1), so window managers that find an app's windows by its pid never see the window (#163). The+/// host still checks in as the app, from inside it; a signal to the launcher is passed on to it.+fn launcher(name: &str, size: (u32, u32)) -> String {+ format!(+ "#!/bin/sh\n# made by raea app bundle: the page in raea-page-host's window, the host this script's child (an exec loses the app's pid)\nR=\"$(cd \"$(dirname \"$0\")/../Resources\" && pwd)\"\n\"$R/raea-page-host\" \"$R/app.js\" --css \"$R/app.css\" --window --title {} --size {}x{} &\nhost=$!\ntrap 'kill -TERM \"$host\" 2>/dev/null' TERM INT HUP\nwait \"$host\"\n",+ sh(name),+ size.0,+ size.1+ )+}+/// The bundle id from the title: ascii letters and digits, under app.raea.localfn bundle_id(title: &str) -> String {let id: String = title.chars().filter(|c| c.is_ascii_alphanumeric()).collect::<String>().to_lowercase();@@ -58,20 +73,54 @@ pub fn web(a: &Ask) -> Result<String, String> {std::fs::copy(&host, res.join("raea-page-host")).map_err(|e| format!("{}: {e}", host.display()))?;let name = &a.title;std::fs::write(contents.join("Info.plist"), plist(name, &bundle_id(name))).map_err(|e| e.to_string())?;- let launcher = macos.join(name);- let script = format!(- "#!/bin/sh\n# made by raea app bundle: the page in raea-page-host's window\nR=\"$(cd \"$(dirname \"$0\")/../Resources\" && pwd)\"\nexec \"$R/raea-page-host\" \"$R/app.js\" --css \"$R/app.css\" --window --title {} --size {}x{}\n",- sh(name),- a.size.0,- a.size.1- );- std::fs::write(&launcher, script).map_err(|e| e.to_string())?;+ let exe = macos.join(name);+ std::fs::write(&exe, launcher(name, a.size)).map_err(|e| e.to_string())?;#[cfg(unix)]{use std::os::unix::fs::PermissionsExt;- std::fs::set_permissions(&launcher, std::fs::Permissions::from_mode(0o755)).map_err(|e| e.to_string())?;+ std::fs::set_permissions(&exe, std::fs::Permissions::from_mode(0o755)).map_err(|e| e.to_string())?;}let mut said = crate::sign::sign(&out, &a.sign)?;said.push(format!("{} (web)", out.display()));Ok(said.join("\n"))}++#[cfg(all(test, unix))]+mod tests {+ use std::os::unix::fs::PermissionsExt;+ use std::process::Command;++ /// The launcher run as macOS runs an app's executable, with a page host that writes down its own pid, its parent's+ /// and its arguments, and exits 3: the host must be the launcher's child (an exec ran it in the launcher's+ /// process, the pid macOS launched, and AppKit lost the app's pid: #163), on the app's files, and the launcher must+ /// end with the host's status.+ #[test]+ fn the_host_runs_as_the_launchers_child() {+ // canonical, so the launcher's own `pwd` names Resources as this test does (macOS's temp folder is a link)+ let dir = std::env::temp_dir().canonicalize().unwrap().join(format!("raea-macapp-launcher-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ let (macos, res) = (dir.join("T.app/Contents/MacOS"), dir.join("T.app/Contents/Resources"));+ std::fs::create_dir_all(&macos).unwrap();+ std::fs::create_dir_all(&res).unwrap();+ let ran = res.join("ran");+ let host = res.join("raea-page-host");+ std::fs::write(&host, format!("#!/bin/sh\necho \"$$ $PPID $*\" > '{}'\nexit 3\n", ran.display())).unwrap();+ let exe = macos.join("T");+ std::fs::write(&exe, super::launcher("My App", (800, 600))).unwrap();+ for f in [&host, &exe] {+ std::fs::set_permissions(f, std::fs::Permissions::from_mode(0o755)).unwrap();+ }+ let mut child = Command::new(&exe).spawn().unwrap();+ let launched = child.id().to_string();+ let status = child.wait().unwrap();+ let said = std::fs::read_to_string(&ran).unwrap();+ let mut words = said.split_whitespace();+ let (pid, parent) = (words.next().unwrap(), words.next().unwrap());+ assert_ne!(pid, launched, "the host ran in the launcher's own process (exec'd): {said}");+ assert_eq!(parent, launched, "the host isn't the launcher's child: {said}");+ let args = format!("{0}/app.js --css {0}/app.css --window --title My App --size 800x600", res.display());+ assert_eq!(said.trim_end().splitn(3, ' ').nth(2), Some(args.as_str()));+ assert_eq!(status.code(), Some(3), "the launcher didn't end with the host's status");+ let _ = std::fs::remove_dir_all(&dir);+ }+}diff --git a/engine/page/window/src/native.rs b/engine/page/window/src/native.rsindex 6564f7d6..2d57868f 100644--- a/engine/page/window/src/native.rs+++ b/engine/page/window/src/native.rs@@ -14,8 +14,9 @@//!//! Live only on screen (--window) and without RAEA_NO_OPEN=1: otherwise every call is recorded and answered as if done,//! so headless runs never touch the person's clipboard, browser or notifications. Notifications and raea:// links need-//! the app's identity: the window running as raea.app's own process (tools/raea-app/launch.sh execs it from-//! Contents/MacOS); elsewhere notify answers an error that says so.+//! the app's identity: the window's program in raea.app's Contents/MacOS, which makes raea.app its main bundle+//! (tools/raea-app/launch.sh starts it there as its child, never exec'd: an exec left the app without a pid in AppKit,+//! #163); elsewhere notify answers an error that says so.//! AppKit is called on the main thread: the calls queue here and `drain` (a NonSend system) runs them.use std::sync::Mutex;