Skip to content

Commit

Permalink
Refactor TouchScreen.Tap slightly for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Apr 18, 2024
1 parent 1c143e5 commit fcbd86a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions common/touchscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,34 @@ func NewTouchscreen(ctx context.Context, s session, k *Keyboard) *Touchscreen {
}
}

// Tap dispatches a tap start and tap end event.
func (t *Touchscreen) Tap(x float64, y float64) error {
if err := t.tap(x, y); err != nil {
return fmt.Errorf("tapping: %w", err)
}
return nil
}

func (t *Touchscreen) tap(x float64, y float64) error {
action := input.DispatchTouchEvent(input.TouchStart, []*input.TouchPoint{{X: x, Y: y}}).
WithModifiers(input.Modifier(t.keyboard.modifiers))
if err := action.Do(cdp.WithExecutor(t.ctx, t.session)); err != nil {
touchStart := input.DispatchTouchEvent(
input.TouchStart,
[]*input.TouchPoint{{X: x, Y: y}},
).WithModifiers(
input.Modifier(t.keyboard.modifiers),
)
if err := touchStart.Do(cdp.WithExecutor(t.ctx, t.session)); err != nil {
return fmt.Errorf("touch start: %w", err)
}

action = input.DispatchTouchEvent(input.TouchEnd, []*input.TouchPoint{}).
WithModifiers(input.Modifier(t.keyboard.modifiers))
if err := action.Do(cdp.WithExecutor(t.ctx, t.session)); err != nil {
touchEnd := input.DispatchTouchEvent(
input.TouchEnd,
[]*input.TouchPoint{},
).WithModifiers(
input.Modifier(t.keyboard.modifiers),
)
if err := touchEnd.Do(cdp.WithExecutor(t.ctx, t.session)); err != nil {
return fmt.Errorf("touch end: %w", err)
}

return nil
}

// Tap dispatches a tap start and tap end event.
func (t *Touchscreen) Tap(x float64, y float64) error {
if err := t.tap(x, y); err != nil {
return fmt.Errorf("tapping: %w", err)
}
return nil
}

0 comments on commit fcbd86a

Please sign in to comment.