(
udid: &str,
)
| 792 | } |
| 793 | |
| 794 | async fn discover_launchd_webinspector_socket( |
| 795 | udid: &str, |
| 796 | ) -> Result<Option<WebKitSocket>, AppError> { |
| 797 | let output = match timeout( |
| 798 | WEBKIT_SOCKET_DISCOVERY_TIMEOUT, |
| 799 | Command::new("xcrun") |
| 800 | .args([ |
| 801 | "simctl", |
| 802 | "spawn", |
| 803 | udid, |
| 804 | "launchctl", |
| 805 | "getenv", |
| 806 | "RWI_LISTEN_SOCKET", |
| 807 | ]) |
| 808 | .output(), |
| 809 | ) |
| 810 | .await |
| 811 | { |
| 812 | Ok(Ok(output)) => output, |
| 813 | Ok(Err(error)) => { |
| 814 | debug!("Unable to query simulator launchd WebKit socket for {udid}: {error}"); |
| 815 | return Ok(None); |
| 816 | } |
| 817 | Err(_) => { |
| 818 | debug!("Timed out querying simulator launchd WebKit socket for {udid}."); |
| 819 | return Ok(None); |
| 820 | } |
| 821 | }; |
| 822 | |
| 823 | if !output.status.success() { |
| 824 | debug!( |
| 825 | "Simulator launchd did not report WebKit socket for {udid}: {}", |
| 826 | String::from_utf8_lossy(&output.stderr).trim() |
| 827 | ); |
| 828 | return Ok(None); |
| 829 | } |
| 830 | |
| 831 | let stdout = String::from_utf8_lossy(&output.stdout); |
| 832 | let Some(path) = sanitize_webinspectord_socket_path(&stdout) else { |
| 833 | return Ok(None); |
| 834 | }; |
| 835 | |
| 836 | if !Path::new(path).exists() { |
| 837 | debug!("Simulator launchd WebKit socket for {udid} does not exist: {path}"); |
| 838 | return Ok(None); |
| 839 | } |
| 840 | |
| 841 | Ok(Some(WebKitSocket { |
| 842 | path: path.to_owned(), |
| 843 | })) |
| 844 | } |
| 845 | |
| 846 | fn sanitize_webinspectord_socket_path(raw: &str) -> Option<&str> { |
| 847 | let path = raw.trim(); |
no test coverage detected