Skip to content

Commit

Permalink
accessibility: raise RpcFailedToGetPrimaryAppError if failed to get it
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Oct 22, 2024
1 parent 7e9c3df commit e1e7445
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/rpcclient/rpcclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ResponseNotFoundError(RpcClientException):

class ServerResponseError(RpcClientException):
""" Server returned error """

def __init__(self, error):
super().__init__()
self.error = error
Expand Down Expand Up @@ -197,3 +198,8 @@ class RpcXpcSerializationError(RpcXpcError):
class RpcSetDeveloperModeError(BadReturnValueError):
""" Failed to set Developer Mode """
pass


class RpcFailedToGetPrimaryAppError(BadReturnValueError):
""" Failed to get [AXElement primaryApp] """
pass
7 changes: 5 additions & 2 deletions src/rpcclient/rpcclient/ios/accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from rpcclient.darwin.symbol import DarwinSymbol
from rpcclient.exceptions import ElementNotFoundError, FirstElementNotFoundError, LastElementNotFoundError, \
MissingLibraryError, RpcAccessibilityTurnedOffError
MissingLibraryError, RpcAccessibilityTurnedOffError, RpcFailedToGetPrimaryAppError
from rpcclient.structs.consts import RTLD_NOW


Expand Down Expand Up @@ -393,7 +393,10 @@ def __init__(self, client):
def primary_app(self) -> AXElement:
if not self.enabled:
raise RpcAccessibilityTurnedOffError()
return self.axelement(self._client.symbols.objc_getClass('AXElement').objc_call('primaryApp'))
primary_app = self._client.symbols.objc_getClass('AXElement').objc_call('primaryApp')
if primary_app == 0:
raise RpcFailedToGetPrimaryAppError()
return self.axelement(primary_app)

@property
def enabled(self) -> bool:
Expand Down

0 comments on commit e1e7445

Please sign in to comment.