MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / create_simulator

Function create_simulator

packages/server/src/api/routes.rs:1762–1885  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    Json(payload): Json<CreateSimulatorPayload>,
)

Source from the content-addressed store, hash-verified

1760}
1761
1762async fn create_simulator(
1763 State(state): State<AppState>,
1764 Json(payload): Json<CreateSimulatorPayload>,
1765) -> Result<Json<Value>, AppError> {
1766 let platform = payload.platform.as_deref().map(str::trim).unwrap_or("ios");
1767 let name = payload.name.trim().to_owned();
1768 let device_type_identifier = payload.device_type_identifier.trim().to_owned();
1769 if name.is_empty() {
1770 return Err(AppError::bad_request("Request body must include `name`."));
1771 }
1772 if device_type_identifier.is_empty() {
1773 return Err(AppError::bad_request(
1774 "Request body must include `deviceTypeIdentifier`.",
1775 ));
1776 }
1777
1778 let runtime_identifier = trimmed_optional_string(payload.runtime_identifier);
1779 if platform.eq_ignore_ascii_case("android") {
1780 let system_image_identifier = runtime_identifier.ok_or_else(|| {
1781 AppError::bad_request("Android emulator creation requires `runtimeIdentifier`.")
1782 })?;
1783 if payload.paired_watch.is_some() {
1784 return Err(AppError::bad_request(
1785 "Android emulator creation does not support `pairedWatch`.",
1786 ));
1787 }
1788 let spec = AndroidEmulatorSpec {
1789 name,
1790 device_profile_identifier: device_type_identifier,
1791 system_image_identifier,
1792 };
1793 let created =
1794 run_android_action(state.clone(), move |android| android.create_emulator(spec)).await?;
1795 let udid = created
1796 .get("udid")
1797 .and_then(Value::as_str)
1798 .ok_or_else(|| AppError::internal("Android create did not return an emulator ID."))?
1799 .to_owned();
1800 boot_android_device(state.clone(), udid.clone()).await?;
1801 let devices = all_device_values(state, true).await?;
1802 let simulator = devices
1803 .iter()
1804 .find(|entry| entry.get("udid").and_then(Value::as_str) == Some(udid.as_str()))
1805 .cloned()
1806 .ok_or_else(|| {
1807 AppError::not_found(format!("Created emulator {udid} was not found."))
1808 })?;
1809 return Ok(json(json_value!({
1810 "ok": true,
1811 "created": created,
1812 "simulator": simulator,
1813 "pairedWatchSimulator": null,
1814 })));
1815 }
1816
1817 let paired_watch = payload
1818 .paired_watch
1819 .map(|watch| {

Callers

nothing calls this directly

Calls 13

trimmed_optional_stringFunction · 0.85
run_android_actionFunction · 0.85
boot_android_deviceFunction · 0.85
all_device_valuesFunction · 0.85
jsonFunction · 0.85
run_bridge_actionFunction · 0.85
boot_ios_deviceFunction · 0.85
is_emptyMethod · 0.80
create_emulatorMethod · 0.80
create_simulatorMethod · 0.80
cloneMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected