Skip to main content

Mountain/IPC/WindServiceHandlers/NativeHost/
IsRunningUnderARM64Translation.rs

1#![allow(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 Fn() -> 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
15		let IsTranslated = *ROSETTA.get_or_init(|| {
16			std::process::Command::new("sysctl")
17				.args(["-n", "sysctl.proc_translated"])
18				.output()
19				.ok()
20				.map(|O| String::from_utf8_lossy(&O.stdout).trim() == "1")
21				.unwrap_or(false)
22		});
23
24		Ok(json!(IsTranslated))
25	}
26
27	#[cfg(not(target_os = "macos"))]
28	{
29		Ok(json!(false))
30	}
31}