Skip to main content

Mountain/IPC/WindServiceHandlers/Terminal/
DetachFromProcess.rs

1
2//! `localPty:detachFromProcess` - signal that the workbench is detaching
3//! from a live PTY (e.g. on window close while keeping the process alive).
4//!
5//! Mountain keeps the PTY running. The PTY output buffer continues to
6//! accumulate so that `sky:replay-events` can replay missed data when the
7//! window reattaches. Returns `null` unconditionally - the workbench treats
8//! any truthy resolve as "detach acknowledged".
9//!
10//! Wire shape: `Arguments[0]` = id (u64)
11
12use std::sync::Arc;
13
14use serde_json::Value;
15
16use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
17
18pub async fn Fn(_RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
19	let TerminalId = match Arguments.first() {
20		Some(Value::Number(N)) => N.as_u64().unwrap_or(0),
21
22		Some(Value::Object(Obj)) => Obj.get("id").and_then(Value::as_u64).unwrap_or(0),
23
24		_ => 0,
25	};
26
27	dev_log!(
28		"terminal",
29		"[DetachFromProcess] id={} (PTY kept alive; output buffer accumulating for next attach)",
30		TerminalId
31	);
32
33	// Mountain intentionally keeps the PTY alive - no action needed.
34	// The next `localPty:attachToProcess` or `sky:replay-events` will
35	// drain the output buffer back to the renderer.
36	Ok(Value::Null)
37}