Caner 8 months ago
parent
commit
2b66cd0494
1 changed files with 30 additions and 32 deletions
  1. 30 32
      main.py

+ 30 - 32
main.py

@@ -1,4 +1,5 @@
 import subprocess
+import asyncio
 from time import sleep
 from pymobiledevice3.lockdown import create_using_usbmux
 from pymobiledevice3.services.dvt.instruments.process_control import ProcessControl
@@ -9,22 +10,18 @@ from pymobiledevice3.remote.remote_service_discovery import RemoteServiceDiscove
 import threading
 
 BUNDLE_ID = 'com.laiwang.DingTalk'
+PCPWD = 'd123456'
 
-# def channel():
-    # pymobiledevice3 remote start-tunnel
-    # while True:
-    #     # RemoteService.connect()
-
-if __name__ == '__main__':
+async def main():
     try:
-        # 启动隧道服务线程
-        remoteServvice = RemoteService(RemoteServiceDiscoveryService(('127.0.0.1',7777)),'test')
-        remoteServvice.connect()
+        # 初始化管道服务
+        remoteService = RemoteService(RemoteServiceDiscoveryService(('127.0.0.1',7777)),'test')
+        await remoteService.connect()
         # 使用命令方式启动管道
         # try:
         #     # 使用 -S 参数让 sudo 从 stdin 读取密码
         #     result = subprocess.run(
-        #         ["sudo", "-S"] + "pymobiledevice3 remote start-tunnel".split(),
+        #         ["sudo", "-S"] + PCPWD.split(),
         #         input="d123456\n",  # 实际应用中应从安全来源获取
         #         text=True,
         #         capture_output=True,
@@ -35,29 +32,30 @@ if __name__ == '__main__':
         # except subprocess.CalledProcessError as e:
         #     print(f"命令执行失败 (退出码: {e.returncode}):")
         #     print("错误输出:", e.stderr)
-        sleep(3)
-        # 连接手机
-        lockdown = create_using_usbmux()
-        print("开发者模式",lockdown.developer_mode_status)
-        # 获取钉钉-app
-        with InstallationProxyService(lockdown) as installer:
-            # 查找特定应用
-            ddApp = [app for app in installer.get_apps() if 'DingTalk' in app]
-            if len(ddApp):
-                print("找到包",ddApp[0])
-                if ddApp[0] == BUNDLE_ID:
-                    # 打开app
-                    with DvtSecureSocketProxyService(lockdown) as dvt:
-                        process_control = ProcessControl(dvt)
-                        pid = process_control.launch(BUNDLE_ID)
-                        print("启动app",pid)
-                else:
-                    print("包名不匹配")
-            else:
-                print("没找到包,请安装钉钉")
+        # sleep(3)
+        # # 连接手机
+        # lockdown = create_using_usbmux()
+        # print("开发者模式",lockdown.developer_mode_status)
+        # # 获取钉钉-app
+        # with InstallationProxyService(lockdown) as installer:
+        #     # 查找特定应用
+        #     ddApp = [app for app in installer.get_apps() if 'DingTalk' in app]
+        #     if len(ddApp):
+        #         print("找到包",ddApp[0])
+        #         if ddApp[0] == BUNDLE_ID:
+        #             # 打开app
+        #             with DvtSecureSocketProxyService(lockdown) as dvt:
+        #                 process_control = ProcessControl(dvt)
+        #                 pid = process_control.launch(BUNDLE_ID)
+        #                 print("启动app",pid)
+        #         else:
+        #             print("包名不匹配")
+        #     else:
+        #         print("没找到包,请安装钉钉")
 
     except ConnectionError as e:
-        print(f"连接失败")
-
+        print(f"连接失败")    
 
 
+if __name__ == '__main__':
+    asyncio.run(main())