52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
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(
|
|
start_x: float,
|
|
start_y: float,
|
|
end_x: float,
|
|
end_y: float,
|
|
*,
|
|
duration_ms: int = 500,
|
|
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",
|
|
"start": {"x": start_x, "y": start_y},
|
|
"end": {"x": end_x, "y": end_y},
|
|
"waypoints": waypoints,
|
|
"duration_ms": dms,
|
|
}
|
|
get_driver(device_id, manager=manager).swipe(
|
|
start_x, start_y, end_x, end_y, duration_ms
|
|
)
|
|
return {
|
|
"ok": True,
|
|
"action": "swipe",
|
|
"start": {"x": start_x, "y": start_y},
|
|
"end": {"x": end_x, "y": end_y},
|
|
"duration_ms": duration_ms,
|
|
} |