diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 52aea8b..23ed168 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -33,10 +33,13 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Lint with flake8 + - name: Install dependencies run: | - python -m pip install flake8 - flake8 . --max-complexity=14 --max-line-length=127 --statistics + python3 -m pip install --upgrade pip + python3 -m pip install pre-commit + - name: Run pre-commit hooks + run: | + pre-commit run --all-files - name: Verify sorted imports run: | python -m pip install isort diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f5e8132 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +# .pre-commit-config.yaml +repos: + - repo: https://github.com/pre-commit/mirrors-isort + rev: v5.9.3 + hooks: + - id: isort + args: [ '-m', 'HANGING_INDENT', '-l', '120','--check-only' ] + files: src/client + + - repo: https://github.com/pycqa/flake8 + rev: "7.0.0" + hooks: + - id: flake8 + args: [ '--max-line-length=127' ] + files: src/client \ No newline at end of file diff --git a/src/rpcclient/rpcclient/darwin/keychain.py b/src/rpcclient/rpcclient/darwin/keychain.py index bafecc0..be17109 100644 --- a/src/rpcclient/rpcclient/darwin/keychain.py +++ b/src/rpcclient/rpcclient/darwin/keychain.py @@ -5,6 +5,7 @@ logger = logging.getLogger(__name__) + class Keychain: """ keychain utils """ diff --git a/src/rpcclient/rpcclient/exceptions.py b/src/rpcclient/rpcclient/exceptions.py index 2977425..5ca3220 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 25f4d04..7e1f5cb 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: