增加启动校验
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
|
||||
|
||||
...
|
||||
# ---------------- 原来代码不变,只替换下面一个函数 ----------------
|
||||
|
||||
@@ -151,6 +151,12 @@ def deviceList():
|
||||
LogManager.error("获取设备列表失败:", e)
|
||||
return ResultData(data=[]).toJson()
|
||||
|
||||
# 传递token
|
||||
@app.route('/passToken', methods=['POST'])
|
||||
def passToken():
|
||||
data = request.get_json()
|
||||
print(data)
|
||||
return ResultData(data="").toJson()
|
||||
|
||||
# 获取设备应用列表
|
||||
@app.route('/deviceAppList', methods=['POST'])
|
||||
@@ -400,7 +406,6 @@ def monitorMessages():
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
thread = threading.Thread(target=manager.replyMessages, args=(udid, event))
|
||||
thread.start()
|
||||
# 添加到线程管理
|
||||
ThreadManager.add(udid, thread, event)
|
||||
return ResultData(data="").toJson()
|
||||
|
||||
@@ -2,9 +2,6 @@ import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import wda
|
||||
|
||||
import tidevice
|
||||
from Module.DeviceInfo import DeviceInfo
|
||||
from Module.FlaskSubprocessManager import FlaskSubprocessManager
|
||||
from Utils.DevDiskImageDeployer import DevDiskImageDeployer
|
||||
@@ -27,32 +24,19 @@ if "--role=flask" in sys.argv:
|
||||
_run_flask_role()
|
||||
sys.exit(0)
|
||||
|
||||
def main(arg):
|
||||
print(arg)
|
||||
if len(arg) != 2:
|
||||
sys.exit(0)
|
||||
else:
|
||||
if arg[1] != "iosai":
|
||||
sys.exit(0)
|
||||
|
||||
# 项目入口
|
||||
if __name__ == "__main__":
|
||||
|
||||
wda.debug = True
|
||||
|
||||
# 1. 打包环境
|
||||
if hasattr(sys, '_MEIPASS'):
|
||||
base_dir = sys._MEIPASS
|
||||
# 2. 源码调试环境
|
||||
else:
|
||||
base_dir = os.path.dirname(
|
||||
os.path.dirname(os.path.abspath(__file__)) # 向上跳一级
|
||||
)
|
||||
|
||||
# 3. 拼 iproxy 目录
|
||||
iproxy_dir = os.path.join(base_dir, 'resources', 'iproxy')
|
||||
|
||||
# 4. 剩余逻辑不变
|
||||
if os.path.isdir(iproxy_dir):
|
||||
sep = os.pathsep
|
||||
old_path = os.environ.get('PATH', '')
|
||||
if iproxy_dir not in old_path:
|
||||
os.environ['PATH'] = old_path + sep + iproxy_dir
|
||||
else:
|
||||
print(f'warning: {iproxy_dir} not found', file=sys.stderr)
|
||||
# 获取启动时候传递的参数
|
||||
main(sys.argv)
|
||||
|
||||
# 添加iOS开发包到电脑上
|
||||
deployer = DevDiskImageDeployer(verbose=True)
|
||||
@@ -69,15 +53,13 @@ if __name__ == "__main__":
|
||||
except Exception as e:
|
||||
print("[WARN] Device listener not running:", e)
|
||||
|
||||
|
||||
# === 保活:阻塞主线程,直到收到 Ctrl+C/关闭 ===
|
||||
import threading, time, signal
|
||||
|
||||
stop = threading.Event()
|
||||
|
||||
def _handle(_sig, _frm):
|
||||
stop.set()
|
||||
|
||||
|
||||
# Windows 上 SIGINT/SIGTERM 都可以拦到
|
||||
try:
|
||||
signal.signal(signal.SIGINT, _handle)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user