1313
1414from threading import Thread
1515from time import sleep
16+ from typing import Union
1617
1718import requests
1819from packaging .version import Version
@@ -165,7 +166,7 @@ def get_device(id, device_id, ipc_client):
165166 with create_using_usbmux (device_id , autopair = False ) as lockdown :
166167 reply = {"id" : id , "state" : "completed" , "result" : lockdown .short_info }
167168 write_dispatcher .write_reply (ipc_client , reply )
168- except NoDeviceConnectedError | DeviceNotFoundError :
169+ except Union [ NoDeviceConnectedError , DeviceNotFoundError ] :
169170 reply = {"id" : id , "state" : "failed_expected" }
170171 write_dispatcher .write_reply (ipc_client , reply )
171172
@@ -199,6 +200,27 @@ def progress_handler(progress, *args):
199200
200201 print ("Installed bundle: " + str (bundle_identifier ))
201202
203+ def get_bundle_identifier (id , path , ipc_client ):
204+ info_plist_path = Path (path ) / "Info.plist"
205+ with open (info_plist_path , 'rb' ) as f :
206+ plist_data = plistlib .load (f )
207+
208+ bundle_identifier = plist_data ["CFBundleIdentifier" ]
209+
210+ reply = {"id" : id , "state" : "completed" , "result" : bundle_identifier }
211+ write_dispatcher .write_reply (ipc_client , reply )
212+
213+ def get_installed_path (id , lockdown_client , bundle_identifier , ipc_client ):
214+ with InstallationProxyService (lockdown = lockdown_client ) as installer :
215+ res = installer .lookup (options = {"BundleIDs" : [bundle_identifier ]})
216+
217+ if bundle_identifier not in res :
218+ reply = {"id" : id , "state" : "not_installed" }
219+ else :
220+ reply = {"id" : id , "state" : "completed" , "result" : res [bundle_identifier ]["Path" ]}
221+
222+ write_dispatcher .write_reply (ipc_client , reply )
223+
202224def decode_plist (id , path , ipc_client ):
203225 with open (path , 'rb' ) as f :
204226 plist_data = plistlib .load (f )
@@ -402,6 +424,9 @@ def handle_command(command, ipc_client):
402424 elif command_type == "get_version" :
403425 get_version (id , ipc_client )
404426 return
427+ elif command_type == "get_bundle_identifier" :
428+ get_bundle_identifier (id , res ["app_path" ], ipc_client )
429+ return
405430
406431 # Now come the device targetted functions
407432 device_id = res ['device_id' ]
@@ -416,6 +441,9 @@ def handle_command(command, ipc_client):
416441 port = res ['port' ] if 'port' in res else 0
417442 debugserver_connect (id , lockdown , port , ipc_client )
418443 return
444+ elif command_type == "get_installed_path" :
445+ get_installed_path (id , lockdown , res ["bundle_identifier" ], ipc_client )
446+ return
419447
420448 except Exception as e :
421449 reply = {"request" : command , "state" : "failed" , "error" : repr (e ), "backtrace" : traceback .format_exc ()}
0 commit comments