调整逻辑,修复bug。

This commit is contained in:
zw
2025-08-18 15:51:09 +08:00
parent f15bfede6f
commit 20e58eeb81
4 changed files with 113 additions and 63 deletions

95
.idea/workspace.xml generated
View File

@@ -5,43 +5,67 @@
</component>
<component name="ChangeListManager">
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/DeviceInfo.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/DeviceInfo.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/bz2.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/bz2.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/getopt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/getopt.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevice_id.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevice_id.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicebackup.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicebackup.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicebackup2.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicebackup2.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicebtlogger.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicebtlogger.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicecrashreport.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicecrashreport.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicedate.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicedate.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicedebug.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicedebug.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicedebugserverproxy.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicedebugserverproxy.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicedevmodectl.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicedevmodectl.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicediagnostics.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicediagnostics.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/ideviceenterrecovery.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/ideviceenterrecovery.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/ideviceimagemounter.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/ideviceimagemounter.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/ideviceinfo.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/ideviceinfo.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicename.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicename.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicenotificationproxy.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicenotificationproxy.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicepair.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicepair.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/ideviceprovision.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/ideviceprovision.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicerestore.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicerestore.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicescreenshot.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicescreenshot.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicesetlocation.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicesetlocation.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/idevicesyslog.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/idevicesyslog.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/inetcat.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/inetcat.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/iproxy.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/iproxy.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/irecovery.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/irecovery.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/libcrypto-3.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/libcrypto-3.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/libcurl.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/libcurl.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/libssl-3.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/libssl-3.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/plistutil.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/plistutil.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/readline.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/readline.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/zip.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/zip.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Module/iproxy/zlib1.dll" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/zlib1.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build.bat" beforeDir="false" afterPath="$PROJECT_DIR$/build.bat" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/IOSAI.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/certifi/cacert.pem" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/cv2/opencv_videoio_ffmpeg4120_64.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/jaraco/text/Lorem ipsum.txt" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/libcrypto-3.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/libffi-8.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/libssl-3.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/numpy.libs/libscipy_openblas64_-43e11ff0749b8cbe0a615c9cf6737e0e.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/numpy.libs/msvcp140-263139962577ecda4cd9469ca360a746.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/python3.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/python312.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/pythoncom312.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/pywintypes312.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/add.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/advertisement.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/back.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/comment.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/icon.ico" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/bz2.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/getopt.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevice_id.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicebackup.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicebackup2.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicebtlogger.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicecrashreport.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicedate.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicedebug.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicedebugserverproxy.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicedevmodectl.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicediagnostics.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/ideviceenterrecovery.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/ideviceimagemounter.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/ideviceinfo.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicename.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicenotificationproxy.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicepair.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/ideviceprovision.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicerestore.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicescreenshot.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicesetlocation.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/idevicesyslog.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/inetcat.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/iproxy.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/irecovery.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/libcrypto-3.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/libcurl.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/libssl-3.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/plistutil.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/readline.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/zip.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/iproxy/zlib1.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/like.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/resources/search.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/tcl86t.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/tk86t.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/vcruntime140.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/vcruntime140_1.dll" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/Main.dist/zlib1.dll" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -127,6 +151,7 @@
<updated>1755259950275</updated>
<workItem from="1755259951484" duration="5216000" />
<workItem from="1755265222367" duration="2238000" />
<workItem from="1755494675056" duration="8665000" />
</task>
<servers />
</component>
@@ -134,6 +159,6 @@
<option name="version" value="3" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/iOSAI$Main.coverage" NAME="Main Coverage Results" MODIFIED="1755265395711" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
<SUITE FILE_PATH="coverage/iOSAI$Main.coverage" NAME="Main Coverage Results" MODIFIED="1755502228064" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
</component>
</project>

View File

@@ -36,7 +36,7 @@ class Deviceinfo(object):
# 监听设备连接(死循环,内部捕获异常)
# ----------------------------
def startDeviceListener(self):
LogManager.info("Device Listener started", "listener")
# LogManager.info("Device Listener started", "listener")
while True:
try:
lists = Usbmux().device_list()
@@ -58,7 +58,6 @@ class Deviceinfo(object):
# 拔出设备处理
self._removeDisconnected(lists)
time.sleep(1)
# ----------------------------
@@ -140,9 +139,8 @@ class Deviceinfo(object):
except Exception:
pass
# ----------------------------
# 路径:打包/源码都能找到根目录、iproxy 目录和 iproxy 可执行文件
# 根目录与 iproxy 可执行文件定位
# ----------------------------
def _base_dir(self) -> Path:
"""
@@ -151,55 +149,82 @@ class Deviceinfo(object):
"""
if getattr(sys, "frozen", False):
return Path(sys.executable).resolve().parent
return Path(__file__).resolve().parents[1] # iOSAI/ 作为根
def _iproxy_dir(self) -> Path:
"""返回打包后的 iproxy 目录(你现在放在 Module/iproxy/"""
return self._base_dir() / "resources" / "iproxy"
return Path(__file__).resolve().parents[1] # iOSAI/ 作为根
def _iproxy_path(self) -> Path:
"""返回 iproxy 可执行文件的完整路径"""
exe = "iproxy.exe" if os.name == "nt" else "iproxy"
base = self._base_dir()
# 常见放置位置(按优先级)
candidates = [
base / "resources" / "iproxy", # 推荐:resources/iproxy/
base / "resources" / "iproxy" / exe # 推荐:打包资源目录
]
for p in candidates:
if p.exists():
print("iproxy 路径为 ", p)
return p
# 打一条清晰的错误便于排查
tried = [str(c) for c in candidates]
raise FileNotFoundError(f"iproxy not found, tried: {tried}")
# ----------------------------
# 端口映射:启动 iproxy(设置 cwd 和 PATH隐藏窗口
# 端口映射:启动 iproxy
# ----------------------------
def relayDeviceScreenPort(self, udid: str) -> Optional[subprocess.Popen]:
try:
iproxy = self._iproxy_path()
iproxy_dir = self._iproxy_dir()
iproxy = self._iproxy_path() # 例如 .../resources/iproxy/iproxy.exe
iproxy_dir = iproxy.parent
if not iproxy.exists():
raise FileNotFoundError(f"iproxy not found: {iproxy}")
# 继承环境并把 iproxy 目录加入 PATH方便 DLL 解析
# 继承环境并把 iproxy 目录加入 PATH放最前
env = os.environ.copy()
env["PATH"] = str(iproxy_dir) + os.pathsep + env.get("PATH", "")
# 可选:帮助本进程解析该目录下 DLLpy3.8+
try:
os.add_dll_directory(str(iproxy_dir))
except Exception:
pass
# Windows 隐藏子进程窗口
CREATE_NO_WINDOW = 0x08000000 if os.name == "nt" else 0
creationflags = 0x08000000 if os.name == "nt" else 0
# 绝对路径 + shell=False避免 PATH/别名干扰
args = [str(iproxy), "-u", udid, str(self.screenProxy), "9100"]
# (可选)把子进程输出写到你的日志里,排查更方便
def _pipe_to_log(name: str, stream):
try:
for line in iter(stream.readline, ''):
line = line.rstrip('\r\n')
if line:
LogManager.info(f"[iproxy {name}] {line}", udid)
except Exception:
print("遇到错误了")
pass
p = subprocess.Popen(
["iproxy", "-u", udid, str(self.screenProxy), "9100"],
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=CREATE_NO_WINDOW,
cwd=str(iproxy_dir), # 关键:工作目录设为 iproxy 所在目录
env=env, # 关键:把 iproxy_dir 注入 PATH
text=True, # 你后面如果要读 stdout/stderr 的话更方便
cwd=str(iproxy_dir),
env=env,
shell=False,
text=True,
encoding="utf-8",
bufsize=1
bufsize=1,
creationflags=creationflags,
)
# 启动异步日志转发(不要阻塞主线程;需要时可删除)
try:
import threading
threading.Thread(target=_pipe_to_log, args=("STDOUT", p.stdout), daemon=True).start()
threading.Thread(target=_pipe_to_log, args=("STDERR", p.stderr), daemon=True).start()
except Exception as e:
print("这里有错误")
print(e)
pass
LogManager.info(f"启动 iproxy 成功,本地 {self.screenProxy} -> 设备 9100", udid)
return p

View File

@@ -1,7 +1,7 @@
python -m nuitka Module/Main.py ^
--standalone ^
--msvc=latest ^
--windows-console-mode=force ^
--windows-console-mode=disable ^
--remove-output ^
--output-dir=out ^
--output-filename=IOSAI ^

Binary file not shown.