From e1e7445ea0ff81bfb3e3ef7ff436ad13dcfb291b Mon Sep 17 00:00:00 2001 From: doronz88 Date: Tue, 22 Oct 2024 08:42:04 +0300 Subject: [PATCH] accessibility: raise `RpcFailedToGetPrimaryAppError` if failed to get it --- src/rpcclient/rpcclient/exceptions.py | 6 ++++++ src/rpcclient/rpcclient/ios/accessibility.py | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rpcclient/rpcclient/exceptions.py b/src/rpcclient/rpcclient/exceptions.py index 29774255..5ca3220d 100644 --- a/src/rpcclient/rpcclient/exceptions.py +++ b/src/rpcclient/rpcclient/exceptions.py @@ -15,6 +15,7 @@ class ResponseNotFoundError(RpcClientException): class ServerResponseError(RpcClientException): """ Server returned error """ + def __init__(self, error): super().__init__() self.error = error @@ -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 diff --git a/src/rpcclient/rpcclient/ios/accessibility.py b/src/rpcclient/rpcclient/ios/accessibility.py index 25f4d042..7e1f5cb9 100644 --- a/src/rpcclient/rpcclient/ios/accessibility.py +++ b/src/rpcclient/rpcclient/ios/accessibility.py @@ -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 @@ -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: