diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index db4a3b8..f6e45fc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,43 +5,67 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -127,6 +151,7 @@
1755259950275
+
@@ -134,6 +159,6 @@
-
+
\ No newline at end of file
diff --git a/Module/DeviceInfo.py b/Module/DeviceInfo.py
index 99a1ce0..8772390 100644
--- a/Module/DeviceInfo.py
+++ b/Module/DeviceInfo.py
@@ -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", "")
+ # 可选:帮助本进程解析该目录下 DLL(py3.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
diff --git a/build.bat b/build.bat
index 394b03f..4350f24 100644
--- a/build.bat
+++ b/build.bat
@@ -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 ^
@@ -20,4 +20,4 @@ python -m nuitka Module/Main.py ^
--include-module=idna ^
--include-data-dir="E:/Code/python/iOSAI/resources=resources" ^
--include-data-files="E:/Code/python/iOSAI/resources/iproxy/*=resources/iproxy/" ^
- --windows-icon-from-ico=resources/icon.ico
+ --windows-icon-from-ico=resources/icon.ico
\ No newline at end of file
diff --git a/out/Main.dist/IOSAI.exe b/out/Main.dist/IOSAI.exe
index fd4d8c8..d326a89 100644
Binary files a/out/Main.dist/IOSAI.exe and b/out/Main.dist/IOSAI.exe differ