MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / simulator_state

Function simulator_state

packages/server/src/api/routes.rs:1887–1952  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    Path(udid): Path<String>,
)

Source from the content-addressed store, hash-verified

1885}
1886
1887async fn simulator_state(
1888 State(state): State<AppState>,
1889 Path(udid): Path<String>,
1890) -> Result<Json<Value>, AppError> {
1891 let simulator = if android::is_android_id(&udid) {
1892 let android_devices =
1893 run_android_action(state.clone(), |android| android.list_devices()).await?;
1894 state
1895 .android
1896 .enrich_devices(android_devices)
1897 .into_iter()
1898 .find(|entry| entry.get("udid").and_then(Value::as_str) == Some(udid.as_str()))
1899 .ok_or_else(|| AppError::not_found(format!("Unknown Android emulator {udid}")))?
1900 } else {
1901 all_device_values(state.clone(), true)
1902 .await?
1903 .into_iter()
1904 .find(|entry| entry.get("udid").and_then(Value::as_str) == Some(udid.as_str()))
1905 .ok_or_else(|| AppError::not_found(format!("Unknown simulator {udid}")))?
1906 };
1907
1908 let display = simulator.get("privateDisplay");
1909 let frame_sequence = display
1910 .and_then(|value| value.get("frameSequence"))
1911 .and_then(Value::as_u64)
1912 .unwrap_or(0);
1913 let last_frame_at = display
1914 .and_then(|value| value.get("lastFrameAt"))
1915 .and_then(Value::as_u64)
1916 .unwrap_or(0);
1917 let last_frame_age_ms = if last_frame_at > 0 {
1918 Some(now_ms().saturating_sub(last_frame_at))
1919 } else {
1920 None
1921 };
1922 let is_booted = simulator
1923 .get("isBooted")
1924 .and_then(Value::as_bool)
1925 .unwrap_or(false);
1926 let foreground_app = if is_booted && !android::is_android_id(&udid) {
1927 foreground_app_for_simulator(&state, &udid)
1928 .await
1929 .ok()
1930 .flatten()
1931 } else {
1932 None
1933 };
1934
1935 Ok(json(json_value!({
1936 "udid": udid,
1937 "booted": is_booted,
1938 "displayReady": display
1939 .and_then(|value| value.get("displayReady"))
1940 .and_then(Value::as_bool)
1941 .unwrap_or(false),
1942 "displayStatus": display
1943 .and_then(|value| value.get("displayStatus"))
1944 .and_then(Value::as_str)

Callers

nothing calls this directly

Calls 11

is_android_idFunction · 0.85
run_android_actionFunction · 0.85
all_device_valuesFunction · 0.85
jsonFunction · 0.85
list_devicesMethod · 0.80
enrich_devicesMethod · 0.80
now_msFunction · 0.70
cloneMethod · 0.65
getMethod · 0.65
as_strMethod · 0.45

Tested by

no test coverage detected