refactor(sidecar): implement DoubleTap with the sub-100ms inter-tap gap

This commit is contained in:
pj committed 2026-06-01 22:44:56 +05:30
1 parent 757a41272a
commit 902c8f6e90
1 file changed
+28
+28
View File
@@ -103,6 +103,34 @@ func (c *Client) TapSelector(ctx context.Context, selector string) error {
return err
}
// doubleTapGap is the inter-tap delay for DoubleTap: short enough to land both
// events inside a sub-100 ms race window, long enough for the sidecar to
// serialize two MotionEvent streams. The sidecar exposes no native double-tap
// RPC, so the gesture is two Taps with this gap.
const doubleTapGap = 50 * time.Millisecond
func (c *Client) DoubleTap(ctx context.Context, x, y int) error {
return doubleTap(ctx, func() error { return c.Tap(ctx, x, y) })
}
func (c *Client) DoubleTapSelector(ctx context.Context, selector string) error {
return doubleTap(ctx, func() error { return c.TapSelector(ctx, selector) })
}
func doubleTap(ctx context.Context, tap func() error) error {
if err := tap(); err != nil {
return err
}
timer := time.NewTimer(doubleTapGap)
defer timer.Stop()
select {
case <-ctx.Done():
return ctx.Err()
case <-timer.C:
}
return tap()
}
func (c *Client) InputText(ctx context.Context, text string) error {
_, err := c.stub.InputText(ctx, &driverpb.Text{Value: text})
return err