feat: enhance swipe and back navigation logic
- Adjusted configuration for reset after swipes to 10 seconds and added action to go back. - Updated flow control to skip back action if a recent reset was triggered within 5 seconds. - Implemented a mechanism to enable back navigation when consecutive misses reach a threshold. - Added GUI options to enable or disable back navigation on misses, ensuring consistency with user settings. - Introduced new diagnostic tools for runtime flag checks and screenshot diagnostics. - Created PowerShell scripts for restoring Start Menu shortcuts and performing system health checks. - Added tests for swipe operations and back navigation to validate new logic.
This commit is contained in:
1 parent
0c3a763d63
commit
dcded08796
19 files changed
+936
-22
No files matched your search
+125
-4
@@ -303,6 +303,17 @@ class underlying_operations:
|
||||
# 注释掉全局日志禁用,以便查看详细的计时日志
|
||||
# logging.disable(logging.DEBUG)
|
||||
# logging.disable(logging.WARNING)
|
||||
# 用于短期内记录 get_screenshot 调用来源(用于精确定位高频调用)
|
||||
try:
|
||||
import collections
|
||||
|
||||
self._screenshot_call_cache = collections.deque(maxlen=1000)
|
||||
except Exception:
|
||||
self._screenshot_call_cache = []
|
||||
# 日志文件路径(JSON Lines 格式)
|
||||
self._screenshot_log_path = os.path.join(
|
||||
os.path.dirname(__file__), "logs", "screenshot_calls.jsonl"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _adb() -> str:
|
||||
@@ -498,6 +509,48 @@ class underlying_operations:
|
||||
是否成功获取截图
|
||||
"""
|
||||
start_ts = time_module.time()
|
||||
# Diagnostic: record pre-call info including caller stack (top frames)
|
||||
try:
|
||||
import inspect, json, threading
|
||||
|
||||
frames = []
|
||||
for fr in inspect.stack()[1:9]:
|
||||
frame_info = {
|
||||
"file": os.path.relpath(fr.filename, os.path.dirname(__file__)),
|
||||
"line": fr.lineno,
|
||||
"function": fr.function,
|
||||
}
|
||||
frames.append(frame_info)
|
||||
|
||||
pre_record = {
|
||||
"ts": datetime.now().isoformat(),
|
||||
"device_id": device_id,
|
||||
"use_service": bool(use_service),
|
||||
"path": path,
|
||||
"phase": "start",
|
||||
"thread": threading.get_ident(),
|
||||
"stack": frames,
|
||||
}
|
||||
# cache in memory
|
||||
try:
|
||||
if hasattr(self, "_screenshot_call_cache"):
|
||||
try:
|
||||
self._screenshot_call_cache.append(pre_record)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# append JSON line to log file
|
||||
try:
|
||||
log_dir = os.path.join(os.path.dirname(__file__), "logs")
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
with open(self._screenshot_log_path, "a", encoding="utf-8") as _lf:
|
||||
_lf.write(json.dumps(pre_record, ensure_ascii=False) + "\n")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
# 如果启用服务模式,使用后台截图服务;若服务不可用或返回 False,则回退到直接截图
|
||||
if use_service:
|
||||
try:
|
||||
@@ -527,7 +580,34 @@ class underlying_operations:
|
||||
logging.info(
|
||||
"[截图] 使用后台服务耗时(ms)=%.1f device=%s", dur, device_id
|
||||
)
|
||||
return True
|
||||
# 写结束记录
|
||||
try:
|
||||
import json, threading
|
||||
|
||||
end_record = {
|
||||
"ts": datetime.now().isoformat(),
|
||||
"device_id": device_id,
|
||||
"use_service": True,
|
||||
"path": path,
|
||||
"phase": "end",
|
||||
"result": True,
|
||||
"duration_ms": dur,
|
||||
"thread": threading.get_ident(),
|
||||
}
|
||||
try:
|
||||
if hasattr(self, "_screenshot_call_cache"):
|
||||
self._screenshot_call_cache.append(end_record)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
with open(self._screenshot_log_path, "a", encoding="utf-8") as _lf:
|
||||
_lf.write(json.dumps(end_record, ensure_ascii=False) + "\n")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
# do not return here; let final return at function end
|
||||
result = True
|
||||
else:
|
||||
timetag = datetime.now().strftime("%H:%M:%S")
|
||||
logging.info(
|
||||
@@ -542,6 +622,8 @@ class underlying_operations:
|
||||
timetag,
|
||||
e,
|
||||
)
|
||||
# ensure result exists
|
||||
result = False
|
||||
except ImportError as e:
|
||||
timetag = datetime.now().strftime("%H:%M:%S")
|
||||
logging.warning(
|
||||
@@ -549,23 +631,62 @@ class underlying_operations:
|
||||
timetag,
|
||||
e,
|
||||
)
|
||||
result = False
|
||||
except Exception as e:
|
||||
timetag = datetime.now().strftime("%H:%M:%S")
|
||||
logging.warning(
|
||||
"[%s] [截图操作] 服务模式不可用,回退到直接截图: %s", timetag, e
|
||||
)
|
||||
result = False
|
||||
|
||||
# 原有的直接截图逻辑(保持向后兼容),测量其耗时
|
||||
result = self._get_screenshot_direct(device_id, path)
|
||||
try:
|
||||
# If result already set by service branch, skip direct call
|
||||
if "result" in locals() and locals()["result"] is True:
|
||||
# already successful via service
|
||||
final_result = True
|
||||
else:
|
||||
final_result = self._get_screenshot_direct(device_id, path)
|
||||
except Exception:
|
||||
final_result = False
|
||||
|
||||
dur = (time_module.time() - start_ts) * 1000.0
|
||||
logging.info(
|
||||
"[截图] 总耗时(ms)=%.1f device=%s use_service=%s result=%s",
|
||||
dur,
|
||||
device_id,
|
||||
bool(use_service),
|
||||
result,
|
||||
final_result,
|
||||
)
|
||||
return result
|
||||
|
||||
# 写结束记录(包含持续时长与结果)
|
||||
try:
|
||||
import json, threading
|
||||
|
||||
end_record = {
|
||||
"ts": datetime.now().isoformat(),
|
||||
"device_id": device_id,
|
||||
"use_service": bool(use_service),
|
||||
"path": path,
|
||||
"phase": "end",
|
||||
"result": bool(final_result),
|
||||
"duration_ms": dur,
|
||||
"thread": threading.get_ident(),
|
||||
}
|
||||
try:
|
||||
if hasattr(self, "_screenshot_call_cache"):
|
||||
self._screenshot_call_cache.append(end_record)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
with open(self._screenshot_log_path, "a", encoding="utf-8") as _lf:
|
||||
_lf.write(json.dumps(end_record, ensure_ascii=False) + "\n")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return bool(final_result)
|
||||
|
||||
def _get_screenshot_direct(self, device_id, path="pic"):
|
||||
"""直接截图(不使用服务模式)"""
|
||||
|
||||
Reference in new issue
Block a user