(
State(state): State<AppState>,
Json(payload): Json<CreateSimulatorPayload>,
)
| 1760 | } |
| 1761 | |
| 1762 | async 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| { |
nothing calls this directly
no test coverage detected