Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
IsRunningUnderARM64Translation.rs

1//! Wire method: `nativeHost:isRunningUnderARM64Translation`.
2//! On macOS checks `sysctl.proc_translated` (Rosetta 2). Cached via
3//! `OnceLock` - translation status is stable for the process lifetime.
4
5use serde_json::{Value, json};
6
7pub async fn Fn() -> Result<Value, String> {
8	#[cfg(target_os = "macos")]
9	{
10		// sysctl.proc_translated is stable for the process lifetime.
11		static ROSETTA:std::sync::OnceLock<bool> = std::sync::OnceLock::new();
12
13		let IsTranslated = *ROSETTA.get_or_init(|| {
14			std::process::Command::new("sysctl")
15				.args(["-n", "sysctl.proc_translated"])
16				.output()
17				.ok()
18				.map(|O| String::from_utf8_lossy(&O.stdout).trim() == "1")
19				.unwrap_or(false)
20		});
21
22		Ok(json!(IsTranslated))
23	}
24
25	#[cfg(not(target_os = "macos"))]
26	{
27		Ok(json!(false))
28	}
29}