From fcbd86ab7088b9f7374393bc9168fbdcf6f6149c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 18 Apr 2024 12:17:25 +0300 Subject: [PATCH] Refactor TouchScreen.Tap slightly for clarity --- common/touchscreen.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/common/touchscreen.go b/common/touchscreen.go index 2855fd4a1..d5daa4d5c 100644 --- a/common/touchscreen.go +++ b/common/touchscreen.go @@ -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 -}