Skip to content

Commit

Permalink
Merge pull request #1242 from doronz88/bugfix/accessibility-list-items
Browse files Browse the repository at this point in the history
Bugfix/accessibility list items
  • Loading branch information
doronz88 authored Oct 15, 2024
2 parents 6706704 + fe4393b commit fb9093c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
31 changes: 6 additions & 25 deletions pymobiledevice3/cli/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,33 +860,14 @@ def accessibility_notifications(service_provider: LockdownClient):

@accessibility.command('list-items', cls=Command)
def accessibility_list_items(service_provider: LockdownClient):
"""List items available in the currently shown menu."""
"""List elements available in the currently shown menu."""

service = AccessibilityAudit(service_provider)
iterator = service.iter_events()

# every focus change is expected publish a "hostInspectorCurrentElementChanged:"
service.move_focus_next()

first_item = None
items = []

for event in iterator:
if event.name != 'hostInspectorCurrentElementChanged:':
# ignore any other events
continue

# each such event should contain exactly one element that became in focus
current_item = event.data[0]

if first_item is None:
first_item = current_item
elif first_item.caption == current_item.caption:
return # Break if we encounter the first item again (loop)
elements = []
with AccessibilityAudit(service_provider) as service:
for element in service.iter_elements():
elements.append(element.to_dict())
print_json(elements)

items.append(current_item.to_dict())
print_json(items)
service.move_focus_next()

@developer.group('condition')
def condition():
Expand Down
25 changes: 25 additions & 0 deletions pymobiledevice3/services/accessibilityaudit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing
from dataclasses import dataclass
from enum import Enum, IntEnum
from typing import Generator

from packaging.version import Version

Expand Down Expand Up @@ -413,3 +414,27 @@ def set_setting(self, name: str, value: typing.Any) -> None:
self.broadcast.deviceUpdateAccessibilitySetting_withValue_(
MessageAux().append_obj(setting).append_obj({'ObjectType': 'passthrough', 'Value': value}),
expects_reply=False)

def iter_elements(self) -> Generator[AXAuditInspectorFocus_v1, None, None]:
iterator = self.iter_events()

# every focus change is expected publish a "hostInspectorCurrentElementChanged:"
self.move_focus_next()

first_item = None

for event in iterator:
if event.name != 'hostInspectorCurrentElementChanged:':
# ignore any other events
continue

# each such event should contain exactly one element that became in focus
current_item = event.data[0]

if first_item is None:
first_item = current_item
elif first_item.caption == current_item.caption:
break # Break if we encounter the first item again (loop)

yield current_item
self.move_focus_next()

0 comments on commit fb9093c

Please sign in to comment.