21
21
from tornado .ioloop import IOLoop
22
22
23
23
from freeport import freeport
24
+ from tidevice import Device
25
+ from tidevice ._usbmux import Usbmux
24
26
25
27
DeviceEvent = namedtuple ('DeviceEvent' , ['present' , 'udid' ])
28
+ um = Usbmux ()
26
29
27
30
28
31
def runcommand (* args ) -> str :
@@ -37,19 +40,30 @@ def runcommand(*args) -> str:
37
40
38
41
39
42
def list_devices ():
40
- udids = runcommand ('idevice_id' , '-l' ).splitlines ()
43
+ devices = um .device_list ()
44
+ udids = [device .udid for device in devices ]
41
45
return udids
42
46
43
47
44
48
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"
46
55
47
56
48
57
def udid2product (udid ):
49
58
"""
50
59
See also: https://www.theiphonewiki.com/wiki/Models
51
60
"""
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' )
53
67
models = {
54
68
"iPhone5,1" : "iPhone 5" ,
55
69
"iPhone5,2" : "iPhone 5" ,
@@ -326,9 +340,9 @@ async def run_webdriveragent(self) -> bool:
326
340
elif self .use_tidevice :
327
341
# 明确使用 tidevice 命令启动 wda
328
342
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 ]
330
344
self .run_background (tidevice_cmd , stdout = subprocess .DEVNULL ,
331
- stderr = subprocess .STDOUT )
345
+ stderr = subprocess .STDOUT )
332
346
else :
333
347
self .run_background (
334
348
cmd , stdout = subprocess .DEVNULL ,
@@ -337,12 +351,12 @@ async def run_webdriveragent(self) -> bool:
337
351
self ._wda_port = freeport .get ()
338
352
self ._mjpeg_port = freeport .get ()
339
353
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" ],
342
356
silent = True )
343
357
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" ],
346
360
silent = True )
347
361
348
362
self .restart_wda_proxy ()
0 commit comments