Skip to content

Commit

Permalink
Merge pull request #371 from doronz88/bugfix/handle-no-primary-app
Browse files Browse the repository at this point in the history
accessibility: raise `RpcFailedToGetPrimaryAppError` if failed to get it
  • Loading branch information
doronz88 authored Oct 22, 2024
2 parents 57bccce + 0487af5 commit 5c7dd8b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/rpcclient/rpcclient/darwin/keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

logger = logging.getLogger(__name__)


class Keychain:
""" keychain utils """

Expand Down
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 5c7dd8b

Please sign in to comment.