feat(tools): humanize swipe into curved W3C path when enabled
This commit is contained in:
+26
-6
@@ -2,6 +2,12 @@ from __future__ import annotations
|
||||
|
||||
from device.manager import DeviceManager
|
||||
from tools._device import get_driver
|
||||
from tools.humanize import (
|
||||
get_rng,
|
||||
jitter_duration,
|
||||
load_humanize_config,
|
||||
swipe_waypoints,
|
||||
)
|
||||
|
||||
|
||||
def swipe(
|
||||
@@ -14,12 +20,26 @@ def swipe(
|
||||
device_id: str | None = None,
|
||||
manager: DeviceManager | None = None,
|
||||
) -> dict[str, object]:
|
||||
cfg = load_humanize_config()
|
||||
if cfg.enabled:
|
||||
rng = get_rng()
|
||||
dms = jitter_duration(duration_ms, spread=cfg.duration_spread, rng=rng)
|
||||
waypoints = swipe_waypoints(
|
||||
(start_x, start_y),
|
||||
(end_x, end_y),
|
||||
curvature=cfg.swipe_curvature,
|
||||
n=cfg.swipe_waypoints,
|
||||
rng=rng,
|
||||
)
|
||||
get_driver(device_id, manager=manager).swipe_path(waypoints, dms)
|
||||
return {
|
||||
"ok": True,
|
||||
"action": "swipe",
|
||||
"waypoints": waypoints,
|
||||
"duration_ms": dms,
|
||||
}
|
||||
get_driver(device_id, manager=manager).swipe(
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
duration_ms,
|
||||
start_x, start_y, end_x, end_y, duration_ms
|
||||
)
|
||||
return {
|
||||
"ok": True,
|
||||
@@ -27,4 +47,4 @@ def swipe(
|
||||
"start": {"x": start_x, "y": start_y},
|
||||
"end": {"x": end_x, "y": end_y},
|
||||
"duration_ms": duration_ms,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user