Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
IsRunningUnderARM64Translation.rs

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