feat(tools): humanize tap coordinates; default off in tests
This commit is contained in:
+4
-1
@@ -28,7 +28,10 @@ class HumanizeConfig:
|
||||
|
||||
|
||||
def load_humanize_config(env: Mapping[str, str] | None = None) -> HumanizeConfig:
|
||||
values = env or os.environ
|
||||
if env is None:
|
||||
values: Mapping[str, str] = os.environ
|
||||
else:
|
||||
values = env
|
||||
return HumanizeConfig(
|
||||
enabled=_parse_bool(values.get(ENABLED_ENV), default=True),
|
||||
tap_radius_px=_parse_float(values.get(TAP_RADIUS_ENV), DEFAULT_TAP_RADIUS_PX),
|
||||
|
||||
+7
-2
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from device.manager import DeviceManager
|
||||
from tools._device import get_driver
|
||||
from tools.humanize import get_rng, jitter_point, load_humanize_config
|
||||
|
||||
|
||||
def tap(
|
||||
@@ -11,5 +12,9 @@ def tap(
|
||||
device_id: str | None = None,
|
||||
manager: DeviceManager | None = None,
|
||||
) -> dict[str, object]:
|
||||
get_driver(device_id, manager=manager).tap(x, y)
|
||||
return {"ok": True, "action": "tap", "x": x, "y": y}
|
||||
cfg = load_humanize_config()
|
||||
px, py = x, y
|
||||
if cfg.enabled:
|
||||
px, py = jitter_point(x, y, radius=cfg.tap_radius_px, rng=get_rng())
|
||||
get_driver(device_id, manager=manager).tap(px, py)
|
||||
return {"ok": True, "action": "tap", "x": px, "y": py}
|
||||
|
||||
Reference in New Issue
Block a user