Skip to content

Commit e78e77b

Browse files
Merge pull request #28 from eyotang/master
feat-leave-ios: 移除对iOS的依赖
2 parents 7093d43 + a6a2ee3 commit e78e77b

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ node_modules/
121121
.DS_Store
122122

123123
.vscode/
124+
.idea

idb.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
from tornado.ioloop import IOLoop
2222

2323
from freeport import freeport
24+
from tidevice import Device
25+
from tidevice._usbmux import Usbmux
2426

2527
DeviceEvent = namedtuple('DeviceEvent', ['present', 'udid'])
28+
um = Usbmux()
2629

2730

2831
def runcommand(*args) -> str:
@@ -37,19 +40,30 @@ def runcommand(*args) -> str:
3740

3841

3942
def list_devices():
40-
udids = runcommand('idevice_id', '-l').splitlines()
43+
devices = um.device_list()
44+
udids = [device.udid for device in devices]
4145
return udids
4246

4347

4448
def udid2name(udid: str) -> str:
45-
return runcommand("idevicename", "-u", udid)
49+
devices = um.device_list()
50+
for device in devices:
51+
if device.udid == udid:
52+
d = Device(device.udid)
53+
return d.get_value(no_session=True).get('DeviceName')
54+
return "Unknown"
4655

4756

4857
def udid2product(udid):
4958
"""
5059
See also: https://www.theiphonewiki.com/wiki/Models
5160
"""
52-
pt = runcommand("ideviceinfo", "--udid", udid, "--key", "ProductType")
61+
pt = ""
62+
devices = um.device_list()
63+
for device in devices:
64+
if device.udid == udid:
65+
d = Device(device.udid)
66+
pt = d.get_value(no_session=True).get('ProductType')
5367
models = {
5468
"iPhone5,1": "iPhone 5",
5569
"iPhone5,2": "iPhone 5",
@@ -326,9 +340,9 @@ async def run_webdriveragent(self) -> bool:
326340
elif self.use_tidevice:
327341
# 明确使用 tidevice 命令启动 wda
328342
logger.info("Got param --use-tidevice , use tidevice to launch wda")
329-
tidevice_cmd = ['tidevice', '-u', self.udid, 'wdaproxy', '-B', self.wda_bundle_pattern, '--port', '0']
343+
tidevice_cmd = ['tidevice', '-u', self.udid, 'xctest', '-B', self.wda_bundle_pattern]
330344
self.run_background(tidevice_cmd, stdout=subprocess.DEVNULL,
331-
stderr=subprocess.STDOUT)
345+
stderr=subprocess.STDOUT)
332346
else:
333347
self.run_background(
334348
cmd, stdout=subprocess.DEVNULL,
@@ -337,12 +351,12 @@ async def run_webdriveragent(self) -> bool:
337351
self._wda_port = freeport.get()
338352
self._mjpeg_port = freeport.get()
339353
self.run_background(
340-
["./iproxy.sh",
341-
str(self._wda_port), "8100", self.udid],
354+
["tidevice", '-u', self.udid, 'relay',
355+
str(self._wda_port), "8100"],
342356
silent=True)
343357
self.run_background(
344-
["./iproxy.sh",
345-
str(self._mjpeg_port), "9100", self.udid],
358+
["tidevice", '-u', self.udid, 'relay',
359+
str(self._mjpeg_port), "9100"],
346360
silent=True)
347361

348362
self.restart_wda_proxy()

0 commit comments

Comments
 (0)