diff --git a/tidevice/_device.py b/tidevice/_device.py index 27849a7..39de77d 100644 --- a/tidevice/_device.py +++ b/tidevice/_device.py @@ -878,9 +878,7 @@ def _launch_wda_app(self, conn = self.connect_instruments() channel = conn.make_channel(InstrumentsService.ProcessControl) - conn.call_message(channel, "processIdentifierForBundleIdentifier:", - [bundle_id]) - + conn.call_message(channel, "processIdentifierForBundleIdentifier:", [bundle_id]) # launch app identifier = "launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:" app_path = app_info['Path'] @@ -1111,7 +1109,7 @@ def _record_test_result_callback(m: DTXMessage): def _ready_with_caps_callback(m: DTXMessage): x2.send_dtx_message(m.channel_id, - payload=DTXPayload.build_other(0x03, xctest_configuration), + payload=DTXPayload.build_other(0x03), message_id=m.message_id) x2.register_callback('_XCT_testRunnerReadyWithCapabilities:', _ready_with_caps_callback) diff --git a/tidevice/_safe_socket.py b/tidevice/_safe_socket.py index 668df2c..09c3b10 100644 --- a/tidevice/_safe_socket.py +++ b/tidevice/_safe_socket.py @@ -53,12 +53,19 @@ def __init__(self, addr: Union[str, typing.Tuple[str, int], socket.socket, addr: can be /var/run/usbmuxd or localhost:27015 or (localhost, 27015) """ self._id = acquire_uid() - self._sock = None self._dup_sock = None # keep original sock when switch_to_ssl self._name = None + try: + self._sock = self._connect(addr) + except Exception as e: + raise SocketError("socket connect error") from e + + self._finalizer = weakref.finalize(self, self._cleanup) + + def _connect(self, addr: Union[str, typing.Tuple[str, int], socket.socket, Any]): if isinstance(addr, socket.socket): - self._sock = addr + return addr else: if isinstance(addr, str): if ':' in addr: @@ -71,10 +78,9 @@ def __init__(self, addr: Union[str, typing.Tuple[str, int], socket.socket, raise SocketError("socket unix:{} unable to connect".format(addr)) else: family = socket.AF_INET - self._sock = socket.socket(family, socket.SOCK_STREAM) - self._sock.connect(addr) - - self._finalizer = weakref.finalize(self, self._cleanup) + sock = socket.socket(family, socket.SOCK_STREAM) + sock.connect(addr) + return sock def _cleanup(self): release_uid(self.id)