增加启动校验
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, List
|
||||
import tidevice
|
||||
import wda
|
||||
from tidevice import Usbmux, ConnectionType
|
||||
from tidevice._device import BaseDevice
|
||||
from Entity.DeviceModel import DeviceModel
|
||||
from Entity.Variables import WdaAppBundleId
|
||||
from Module.FlaskSubprocessManager import FlaskSubprocessManager
|
||||
from Utils.LogManager import LogManager
|
||||
|
||||
@@ -46,11 +47,18 @@ class DeviceInfo:
|
||||
def _add_device(self, udid: str):
|
||||
if not self._trusted(udid):
|
||||
return
|
||||
r = self.startWda(udid)
|
||||
if r is False:
|
||||
LogManager.info("启动wda失败")
|
||||
return
|
||||
w, h, s = self._screen_info(udid)
|
||||
if w == 0 or h == 0 or s == 0:
|
||||
print("未获取到设备屏幕信息")
|
||||
return
|
||||
port = self._alloc_port()
|
||||
proc = self._start_iproxy(udid, port)
|
||||
if not proc:
|
||||
return
|
||||
w, h, s = self._screen_info(udid)
|
||||
model = DeviceModel(deviceId=udid, screenPort=port,
|
||||
width=w, height=h, scale=s, type=1)
|
||||
model.ready = True
|
||||
@@ -75,14 +83,30 @@ class DeviceInfo:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def startWda(self, udid):
|
||||
print("进入启动wda方法")
|
||||
try:
|
||||
dev = tidevice.Device(udid)
|
||||
print("获取tidevice对象成功,准备启动wda")
|
||||
dev.app_start(WdaAppBundleId)
|
||||
print("启动wda成功")
|
||||
time.sleep(3)
|
||||
return True
|
||||
except Exception as e:
|
||||
print("启动wda遇到错误:", e)
|
||||
return False
|
||||
|
||||
def _screen_info(self, udid: str):
|
||||
try:
|
||||
c = wda.USBClient(udid, 8100)
|
||||
c.home()
|
||||
size = c.window_size()
|
||||
scale = c.scale
|
||||
return int(size.width), int(size.height), float(scale)
|
||||
except Exception:
|
||||
return 828, 1792, 2.0
|
||||
return 0, 0, 0
|
||||
except Exception as e:
|
||||
print("获取设备信息遇到错误:",e)
|
||||
return 0, 0, 0
|
||||
|
||||
...
|
||||
# ---------------- 原来代码不变,只替换下面一个函数 ----------------
|
||||
|
||||
Reference in New Issue
Block a user