feat: 娣诲姞30鍒嗛挓瓒呮椂淇濇姢鍜屾墜鍔ㄥ彂閫佽繑鍥為敭鍔熻兘

This commit is contained in:
Your Name committed 2025-12-22 05:02:09 +08:00
1 parent fe0098c591
commit 97bda4816f
25 files changed
+22400 -23900

No files matched your search

+52
View File
@@ -325,6 +325,7 @@ class Runner:
counters = dict(self._counters)
fudai_last = dict(self._fudai_last)
wins = list(self._wins[-20:]) # 只返回最近20条
events = list(self._events[-1000:]) # 返回最近1000条事件用于统计
now = time.time()
uptime = 0
@@ -341,6 +342,7 @@ class Runner:
"counters": counters,
"fudai_last": fudai_last,
"wins": wins,
"events": events,
}
def start(self, params: RunParams) -> None:
@@ -633,6 +635,54 @@ class Runner:
self._reader_thread = threading.Thread(target=_reader, daemon=True)
self._reader_thread.start()
def send_back_key(self, device_id: str) -> bool:
"""手动发送返回键到指定设备。
Args:
device_id: 设备ID,如果为空则使用第一个可用设备
Returns:
True if successful, False otherwise
"""
try:
adb_exe = find_adb_executable()
if not adb_exe:
self._on_line("[错误] 未找到 adb.exe")
return False
# 如果没有指定设备ID,尝试获取第一个可用设备
if not device_id or device_id.strip() == "":
devices = list_adb_devices(adb_exe)
if not devices:
self._on_line("[错误] 未找到可用设备")
return False
device_id = devices[0]
# 发送返回键 (keyevent 4)
cmd = [adb_exe, "-s", device_id, "shell", "input", "keyevent", "4"]
proc = subprocess.run(
cmd,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=5.0,
)
if proc.returncode == 0:
self._on_line(f"[手动操作] 已发送返回键到设备: {device_id}")
return True
else:
error_msg = proc.stderr or proc.stdout or "未知错误"
self._on_line(f"[错误] 发送返回键失败: {error_msg}")
return False
except subprocess.TimeoutExpired:
self._on_line("[错误] 发送返回键超时")
return False
except Exception as e:
self._on_line(f"[错误] 发送返回键异常: {str(e)}")
return False
def stop(self) -> None:
if not self.is_running():
@@ -686,3 +736,5 @@ class Runner:
self._proc = None
self._pid = None