Skip to content

Commit 015e943

Browse files
committed
fix: expose inspector sources with native accessibility
1 parent b3c2e10 commit 015e943

1 file changed

Lines changed: 52 additions & 11 deletions

File tree

server/src/api/routes.rs

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const FOREGROUND_APP_ROUTE_TIMEOUT: Duration = Duration::from_millis(1200);
6868
const APP_UPLOAD_FILE_NAME_HEADER: &str = "x-simdeck-filename";
6969
const MAX_APP_UPLOAD_BYTES: usize = 1024 * 1024 * 1024;
7070
const FOREGROUND_PROCESS_PROBE_TIMEOUT: Duration = Duration::from_millis(750);
71+
const ACCESSIBILITY_SOURCE_DISCOVERY_TIMEOUT: Duration = Duration::from_millis(250);
7172
const ACCESSIBILITY_TREE_CACHE_TTL: Duration = Duration::from_secs(5);
7273
const NATIVE_AX_SNAPSHOT_RETRY_ATTEMPTS: usize = 5;
7374
const NATIVE_AX_SNAPSHOT_RETRY_DELAY: Duration = Duration::from_millis(100);
@@ -3884,7 +3885,7 @@ async fn native_ax_accessibility_tree_value(
38843885
include_hidden: bool,
38853886
interactive_only: bool,
38863887
) -> Result<Value, AppError> {
3887-
let available_sources = available_sources_with_native_ax(None);
3888+
let available_sources = native_ax_available_sources(&state, &udid).await;
38883889
match accessibility_snapshot_with_retries(state, udid, None, max_depth, interactive_only).await
38893890
{
38903891
Ok(native_snapshot) => {
@@ -3916,6 +3917,25 @@ async fn native_ax_accessibility_tree_value(
39163917
}
39173918
}
39183919

3920+
async fn native_ax_available_sources(state: &AppState, udid: &str) -> Vec<String> {
3921+
match timeout(
3922+
ACCESSIBILITY_SOURCE_DISCOVERY_TIMEOUT,
3923+
inspector_session_for_state(state, udid),
3924+
)
3925+
.await
3926+
{
3927+
Ok(Ok(session)) => available_sources_with_native_ax(Some(&session)),
3928+
Ok(Err(error)) => {
3929+
tracing::debug!("Native AX source discovery found no inspector for {udid}: {error}");
3930+
available_sources_with_native_ax(None)
3931+
}
3932+
Err(_) => {
3933+
tracing::debug!("Native AX source discovery timed out for {udid}");
3934+
available_sources_with_native_ax(None)
3935+
}
3936+
}
3937+
}
3938+
39193939
async fn accessibility_point(
39203940
State(state): State<AppState>,
39213941
Path(udid): Path<String>,
@@ -4074,15 +4094,7 @@ async fn inspector_session_for_state(
40744094
state: &AppState,
40754095
udid: &str,
40764096
) -> Result<InspectorSession, String> {
4077-
let frontmost_pid = foreground_app_for_simulator_with_cache_ttl(
4078-
state,
4079-
udid,
4080-
INSPECTOR_FOREGROUND_APP_CACHE_TTL,
4081-
)
4082-
.await
4083-
.ok()
4084-
.flatten()
4085-
.map(|foreground| foreground.process_identifier);
4097+
let frontmost_pid = inspector_frontmost_process_identifier(state, udid).await;
40864098
let connected_error = match connected_inspector_session(state, udid, frontmost_pid).await {
40874099
Ok(session) => return Ok(session),
40884100
Err(error) => error,
@@ -4098,6 +4110,19 @@ async fn inspector_session_for_state(
40984110
}
40994111
}
41004112

4113+
async fn inspector_frontmost_process_identifier(state: &AppState, udid: &str) -> Option<i64> {
4114+
match frontmost_process_identifier(state, udid).await {
4115+
Ok(Some(process_identifier)) => return Some(process_identifier),
4116+
Ok(None) | Err(_) => {}
4117+
}
4118+
4119+
foreground_app_for_simulator_with_cache_ttl(state, udid, INSPECTOR_FOREGROUND_APP_CACHE_TTL)
4120+
.await
4121+
.ok()
4122+
.flatten()
4123+
.map(|foreground| foreground.process_identifier)
4124+
}
4125+
41014126
async fn inspector_session_for_process(
41024127
state: &AppState,
41034128
udid: &str,
@@ -5821,7 +5846,8 @@ async fn accessibility_snapshot_with_options(
58215846
mod tests {
58225847
use super::{
58235848
accessibility_point_snapshot, attach_tree_metadata, available_sources_for_snapshot,
5824-
best_inspector_session, chrome_devtools_source_for_session, client_stats_foreground,
5849+
available_sources_with_native_ax, best_inspector_session,
5850+
chrome_devtools_source_for_session, client_stats_foreground,
58255851
compact_accessibility_snapshot, element_matches_selector, first_matching_element,
58265852
inspector_available_sources, inspector_metadata, inspector_session_from_published,
58275853
inspector_session_score, is_inspector_agent_transport_path,
@@ -6322,6 +6348,21 @@ mod tests {
63226348
);
63236349
}
63246350

6351+
#[test]
6352+
fn native_ax_available_sources_preserve_inspector_sources() {
6353+
let session = InspectorSession {
6354+
transport: InspectorSessionTransport::Connected,
6355+
available_sources: vec![SOURCE_REACT_NATIVE.to_owned()],
6356+
info: Value::Null,
6357+
process_identifier: 42,
6358+
};
6359+
6360+
assert_eq!(
6361+
available_sources_with_native_ax(Some(&session)),
6362+
vec![SOURCE_REACT_NATIVE.to_owned(), SOURCE_NATIVE_AX.to_owned()]
6363+
);
6364+
}
6365+
63256366
#[test]
63266367
fn available_sources_for_flutter_snapshot_removes_uikit_fallback() {
63276368
let sources = available_sources_for_snapshot(

0 commit comments

Comments
 (0)