fix: Clean up blank lines and enhance readability across multiple files
- Removed excessive blank lines from various markdown and Python files to improve readability and maintainability. - Ensured consistent formatting across documentation and code files, contributing to overall project clarity. - Enhanced logging mechanisms for better consistency and debugging support.
This commit is contained in:
1 parent
4678adb8f3
commit
efaa3d3adc
36 files changed
+15075
-517
No files matched your search
+84
-20
@@ -1,11 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
def _adb_swipe_direct(device_id: str, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300, operation=None) -> bool:
|
||||
"""直接使用 ADB 内部滑动命令执行滑动操作。
|
||||
|
||||
Args:
|
||||
device_id: 设备 ID
|
||||
start_x: 起始 X 坐标
|
||||
start_y: 起始 Y 坐标
|
||||
end_x: 结束 X 坐标
|
||||
end_y: 结束 Y 坐标
|
||||
duration_ms: 滑动持续时间(毫秒)
|
||||
operation: operation 对象,用于获取 ADB 路径(可选)
|
||||
|
||||
Returns:
|
||||
True 如果成功,False 如果失败
|
||||
"""
|
||||
try:
|
||||
# 获取 ADB 命令路径
|
||||
if operation and hasattr(operation, '_adb'):
|
||||
adb_cmd = operation._adb()
|
||||
else:
|
||||
adb_cmd = os.environ.get("ADB_EXECUTABLE", "adb") or "adb"
|
||||
if not adb_cmd.startswith('"') and not adb_cmd.endswith('"'):
|
||||
adb_cmd = f'"{adb_cmd}"'
|
||||
|
||||
# 直接使用 ADB 命令执行滑动
|
||||
cmd = f"{adb_cmd} -s {device_id} shell input swipe {start_x} {start_y} {end_x} {end_y} {duration_ms}"
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=5.0,
|
||||
text=True,
|
||||
)
|
||||
|
||||
return result.returncode == 0
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def swipe_up_switch_live(analyser: Any) -> None:
|
||||
"""上滑切换到下一个直播间(基础版封装)。
|
||||
|
||||
直接使用 ADB 内部滑动命令,不通过坐标计算。
|
||||
采用 1080x2400 基准坐标,在屏幕中下部向上滑一段距离。
|
||||
"""
|
||||
try:
|
||||
@@ -20,10 +63,11 @@ def swipe_up_switch_live(analyser: Any) -> None:
|
||||
device_id = getattr(analyser, "device_id", "")
|
||||
|
||||
# 基准坐标(1080x2400):从中下部往上滑
|
||||
# 减少滑动距离:从 1700 到 1000,距离约 700 像素(原来约 1000 像素)
|
||||
start_x_base = 540
|
||||
start_y_base = 1700
|
||||
end_x_base = 540
|
||||
end_y_base = 700
|
||||
end_y_base = 1000
|
||||
|
||||
start_x = start_x_base * rx // 1080
|
||||
end_x = end_x_base * rx // 1080
|
||||
@@ -33,7 +77,7 @@ def swipe_up_switch_live(analyser: Any) -> None:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"滑动",
|
||||
"swipe_up_switch_live:上滑切换直播间",
|
||||
"swipe_up_switch_live:上滑切换直播间(使用 ADB 内部滑动)",
|
||||
start_x=start_x_base,
|
||||
start_y=start_y_base,
|
||||
end_x=end_x_base,
|
||||
@@ -49,21 +93,31 @@ def swipe_up_switch_live(analyser: Any) -> None:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 优先调用底层 swipe,失败则静默忽略(不影响主流程)
|
||||
try:
|
||||
# 执行滑动操作:从 (start_x, start_y) 滑到 (end_x, end_y)
|
||||
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, 300)
|
||||
except Exception:
|
||||
# 直接使用 ADB 内部滑动命令
|
||||
# 增加滑动持续时间(从 300ms 增加到 600ms),确保滑动更稳定
|
||||
# 滑动距离约 1000 像素,600ms 的速度更接近真实用户操作
|
||||
swipe_duration_ms = 600
|
||||
success = _adb_swipe_direct(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation)
|
||||
if not success:
|
||||
# 如果失败,尝试使用基准坐标(不缩放)
|
||||
_adb_swipe_direct(device_id, start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms, analyser.operation)
|
||||
# 如果还是失败,回退到 operation.swipe
|
||||
try:
|
||||
# 如果 analyser 自身提供 swipe 封装,则退回到该封装
|
||||
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, 300)
|
||||
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 注意:滑动后的延迟由调用方控制(如 reservation_back_swipe_delay)
|
||||
# 这里不添加额外延迟,避免双重延迟
|
||||
|
||||
|
||||
def swipe_down_back_live(analyser: Any) -> None:
|
||||
"""下滑回退到上一个直播间(基础版封装)。
|
||||
|
||||
直接使用 ADB 内部滑动命令,不通过坐标计算。
|
||||
在直播间内,向下滑动(从上往下)可以回退到上一个直播间。
|
||||
采用 1080x2400 基准坐标,在屏幕中上部向下滑一段距离。
|
||||
注意:这是与 swipe_up_switch_live 相反的方向。
|
||||
@@ -81,10 +135,11 @@ def swipe_down_back_live(analyser: Any) -> None:
|
||||
|
||||
# 基准坐标(1080x2400):从上方往下滑(与上滑切换相反方向)
|
||||
# 回退操作:从上往下滑动(start_y < end_y)
|
||||
# 减少滑动距离:从 800 到 1300,距离约 500 像素(原来约 800 像素)
|
||||
start_x_base = 540
|
||||
start_y_base = 800 # 上方起始位置
|
||||
end_x_base = 540
|
||||
end_y_base = 1600 # 下方结束位置
|
||||
end_y_base = 1300 # 下方结束位置
|
||||
|
||||
start_x = start_x_base * rx // 1080
|
||||
end_x = end_x_base * rx // 1080
|
||||
@@ -94,7 +149,7 @@ def swipe_down_back_live(analyser: Any) -> None:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"滑动",
|
||||
"swipe_down_back_live:下滑回退到上一个直播间",
|
||||
"swipe_down_back_live:下滑回退到上一个直播间(使用 ADB 内部滑动)",
|
||||
start_x=start_x_base,
|
||||
start_y=start_y_base,
|
||||
end_x=end_x_base,
|
||||
@@ -110,13 +165,22 @@ def swipe_down_back_live(analyser: Any) -> None:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 优先调用底层 swipe,失败则静默忽略(不影响主流程)
|
||||
try:
|
||||
# 执行滑动操作:从 (start_x, start_y) 滑到 (end_x, end_y)
|
||||
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, 300)
|
||||
except Exception:
|
||||
# 直接使用 ADB 内部滑动命令
|
||||
# 增加滑动持续时间(从 300ms 增加到 600ms),确保滑动更稳定
|
||||
# 滑动距离约 800 像素,600ms 的速度更接近真实用户操作
|
||||
swipe_duration_ms = 600
|
||||
success = _adb_swipe_direct(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation)
|
||||
if not success:
|
||||
# 如果失败,尝试使用基准坐标(不缩放)
|
||||
_adb_swipe_direct(device_id, start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms, analyser.operation)
|
||||
# 如果还是失败,回退到 operation.swipe
|
||||
try:
|
||||
# 如果 analyser 自身提供 swipe 封装,则退回到该封装
|
||||
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, 300)
|
||||
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 注意:滑动后的延迟由调用方控制(如 reservation_back_swipe_delay)
|
||||
# 这里不添加额外延迟,避免双重延迟
|
||||
Reference in new issue
Block a user