添加未信任状态,优化goios启动逻辑。 此版本为稳定版。

This commit is contained in:
2025-11-27 14:35:58 +08:00
parent 648f6cdfee
commit 68b985115e
2 changed files with 83 additions and 39 deletions

View File

@@ -4,13 +4,15 @@ import time
import threading
import subprocess
from typing import Optional, Callable
from Entity.Variables import WdaAppBundleId
class IOSActivator:
"""
给 iOS17+ 用的 go-ios 激活器(单例):
- 维护一条全局 tunnel 进程
- 流程tunnel start -> pair(重试) -> image auto(致命) -> runwda(多次重试+日志判定成功)
- 流程tunnel start -> pair(可多次重试) -> image auto(致命) -> runwda(多次重试+日志判定成功)
- WDA 启动成功后触发回调 on_wda_ready(udid)
"""
@@ -28,13 +30,13 @@ class IOSActivator:
return cls._instance
def __init__(
self,
ios_path: Optional[str] = None,
pair_timeout: int = 60, # 配对最多等多久
pair_retry_interval: int = 3, # 配对重试间隔
runwda_max_retry: int = 10, # runwda 最大重试次数
runwda_retry_interval: int = 3,# runwda 重试间隔
runwda_wait_timeout: int = 25 # 单次 runwda 等待“成功日志”的超时时间
self,
ios_path: Optional[str] = None,
pair_timeout: int = 60, # 配对最多等多久
pair_retry_interval: int = 3, # 配对重试间隔
runwda_max_retry: int = 10, # runwda 最大重试次数
runwda_retry_interval: int = 3, # runwda 重试间隔
runwda_wait_timeout: int = 25 # 单次 runwda 等待“成功日志”的超时时间
):
if getattr(self, "_inited", False):
return
@@ -59,18 +61,25 @@ class IOSActivator:
self._lock = threading.Lock()
# Windows 隐藏黑框
# ========= 关键:这里改成“真正隐藏窗口”的安全版 =========
self._creationflags = 0
self._startupinfo = None
if os.name == "nt":
try:
# 只用 CREATE_NO_WINDOW不搞 DETACHED_PROCESS / NEW_PROCESS_GROUP 之类的骚操作
self._creationflags = subprocess.CREATE_NO_WINDOW # type: ignore[attr-defined]
except Exception:
self._creationflags = 0
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined]
try:
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined]
except Exception:
# 某些极端环境下可能没有 STARTF_USESHOWWINDOW忽略即可
pass
si.wShowWindow = 0 # SW_HIDE
self._startupinfo = si
# ========= 关键部分结束 =========
self._inited = True
@@ -134,8 +143,9 @@ class IOSActivator:
print(f"[ios][{name}] 读取 stderr 异常: {e}")
def _spawn_tunnel(self):
"""启动 / 复用全局 tunnel"""
"""启动 / 复用全局 tunnel(不隐藏窗口)"""
with IOSActivator._tunnel_lock:
# 已有并且还在跑就复用
if IOSActivator._tunnel_proc is not None and IOSActivator._tunnel_proc.poll() is None:
print("[ios] tunnel 已经在运行,跳过重新启动")
return
@@ -148,8 +158,8 @@ class IOSActivator:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
creationflags=self._creationflags,
startupinfo=self._startupinfo,
creationflags=self._creationflags, # 0不隐藏
startupinfo=self._startupinfo, # None不隐藏
)
except Exception as e:
print("[ios] 启动 tunnel 失败(忽略):", e)
@@ -158,6 +168,7 @@ class IOSActivator:
IOSActivator._tunnel_proc = proc
print("[ios] tunnel 启动成功, PID=", proc.pid)
# 后台吃日志
threading.Thread(
target=self._drain_process_output,
args=(proc, "tunnel"),
@@ -181,6 +192,10 @@ class IOSActivator:
)
text = (out or "") + "\n" + (err or "")
# 打印一份完整输出,方便调试
if text.strip():
print("[ios][pair] output:\n", text.strip())
if "Successfully paired" in text:
print(f"[ios] 设备 {udid} 配对成功")
return
@@ -238,7 +253,7 @@ class IOSActivator:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
creationflags=self._creationflags,
creationflags=self._creationflags, # 0不隐藏
startupinfo=self._startupinfo,
)
except Exception as e:
@@ -255,7 +270,7 @@ class IOSActivator:
continue
print(f"[WDA-LOG] {line}")
lower = line.lower()
# 这里是你实测的“成功特征”
# 你实测的“成功特征”
if "got capabilities" in lower or '"authorized":true' in lower:
success_evt.set()
print(f"[ios] 捕获到 WDA 启动成功日志({tag})udid={udid}")
@@ -316,7 +331,7 @@ class IOSActivator:
def activate_ios17(self, udid: str, on_wda_ready: Optional[Callable[[str], None]] = None) -> None:
print(f"[WDA] iOS17+ 激活开始udid={udid}, 回调={on_wda_ready}")
# 1. tunnel
# 1. 先确保 tunnel 在跑
self._spawn_tunnel()
# 2. 配对