完善tidevice逻辑
This commit is contained in:
@@ -6,11 +6,9 @@ import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, List
|
||||
|
||||
import wda
|
||||
from tidevice import Usbmux, ConnectionType
|
||||
from tidevice._device import BaseDevice
|
||||
|
||||
from Entity.DeviceModel import DeviceModel
|
||||
from Module.FlaskSubprocessManager import FlaskSubprocessManager
|
||||
from Utils.LogManager import LogManager
|
||||
@@ -19,15 +17,12 @@ from Utils.LogManager import LogManager
|
||||
class DeviceInfo:
|
||||
def __init__(self):
|
||||
self._port = 9110
|
||||
self._models: Dict[str, DeviceModel] = {} # udid -> model
|
||||
self._procs: Dict[str, subprocess.Popen] = {} # udid -> iproxy proc
|
||||
self._models: Dict[str, DeviceModel] = {}
|
||||
self._procs: Dict[str, subprocess.Popen] = {}
|
||||
self._manager = FlaskSubprocessManager.get_instance()
|
||||
self._iproxy_path = self._find_iproxy()
|
||||
self._pool = ThreadPoolExecutor(max_workers=6)
|
||||
|
||||
# 可选:10 秒一次扫野进程
|
||||
threading.Thread(target=self._janitor, daemon=True).start()
|
||||
|
||||
# ---------------- 主循环 ----------------
|
||||
def listen(self):
|
||||
while True:
|
||||
@@ -89,13 +84,20 @@ class DeviceInfo:
|
||||
except Exception:
|
||||
return 828, 1792, 2.0
|
||||
|
||||
...
|
||||
# ---------------- 原来代码不变,只替换下面一个函数 ----------------
|
||||
def _start_iproxy(self, udid: str, port: int) -> Optional[subprocess.Popen]:
|
||||
try:
|
||||
# 隐藏窗口的核心参数
|
||||
kw = {"creationflags": subprocess.CREATE_NO_WINDOW}
|
||||
return subprocess.Popen(
|
||||
[self._iproxy_path, "-u", udid, str(port), "9100"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
**kw
|
||||
)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
def _kill(self, proc: Optional[subprocess.Popen]):
|
||||
@@ -124,16 +126,11 @@ class DeviceInfo:
|
||||
base = Path(__file__).resolve().parent.parent
|
||||
name = "iproxy.exe"
|
||||
path = base / "resources" / "iproxy" / name
|
||||
print(str(path))
|
||||
if path.is_file():
|
||||
return str(path)
|
||||
raise FileNotFoundError(f"iproxy 不存在: {path}")
|
||||
|
||||
# ---------------- janitor(扫野进程) ----------------
|
||||
def _janitor(self):
|
||||
while True:
|
||||
time.sleep(10)
|
||||
self._cleanup_orphan_iproxy()
|
||||
|
||||
# ------------ Windows 专用:列出所有 iproxy 命令行 ------------
|
||||
def _get_all_iproxy_cmdlines(self) -> List[str]:
|
||||
try:
|
||||
|
||||
@@ -2,12 +2,10 @@ import json
|
||||
import os
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Any, Dict
|
||||
|
||||
from Entity.AnchorModel import AnchorModel
|
||||
from Utils.AiUtils import AiUtils
|
||||
from Utils.IOSAIStorage import IOSAIStorage
|
||||
from Utils.LogManager import LogManager
|
||||
@@ -19,7 +17,7 @@ from Entity.ResultData import ResultData
|
||||
from Utils.ControlUtils import ControlUtils
|
||||
from Utils.ThreadManager import ThreadManager
|
||||
from script.ScriptManager import ScriptManager
|
||||
from Entity.Variables import anchorList, prologueList, addModelToAnchorList, removeModelFromAnchorList
|
||||
from Entity.Variables import addModelToAnchorList
|
||||
import Entity.Variables as ev
|
||||
from Utils.JsonUtils import JsonUtils
|
||||
|
||||
@@ -268,7 +266,7 @@ def stopScript():
|
||||
udid = body.get("udid")
|
||||
LogManager.method_info(f"接口收到 /stopScript udid={udid}", method="task")
|
||||
code, msg = ThreadManager.stop(udid)
|
||||
return ResultData(code=code, data="", message=msg).toJson()
|
||||
return ResultData(code=code, data=[], message=msg).toJson()
|
||||
|
||||
|
||||
# 关注打招呼
|
||||
@@ -576,7 +574,7 @@ def delete_last_message():
|
||||
def stopAllTask():
|
||||
idList = request.get_json()
|
||||
code, msg = ThreadManager.batch_stop(idList)
|
||||
return ResultData(code, "", msg).toJson()
|
||||
return ResultData(code, [], msg).toJson()
|
||||
|
||||
|
||||
# @app.route("/killWda", methods=['POST'])
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
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,6 +31,27 @@ if "--role=flask" in sys.argv:
|
||||
# 项目入口
|
||||
if __name__ == "__main__":
|
||||
|
||||
wda.debug = True
|
||||
|
||||
# 1. 拿到打包后的临时目录
|
||||
base_dir = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# 2. 构造 resources/iproxy 绝对路径
|
||||
iproxy_dir = os.path.join(base_dir, 'resources', 'iproxy')
|
||||
|
||||
# 3. 如果目录存在就追加到 PATH
|
||||
if os.path.isdir(iproxy_dir):
|
||||
# Windows 用 ; 分隔,Linux/Mac 用 :
|
||||
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)
|
||||
|
||||
|
||||
# 添加iOS开发包到电脑上
|
||||
deployer = DevDiskImageDeployer(verbose=True)
|
||||
deployer.deploy_all()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user