refactor: handlerDoubleTap

This commit is contained in:
lilong.129
2025-05-06 00:52:47 +08:00
parent 48e3d9002e
commit 71dac459e6
7 changed files with 48 additions and 30 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2505060041 v5.0.0-beta-2505060055

View File

@@ -326,12 +326,10 @@ func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error { func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.DoubleTap") log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.DoubleTap")
var err error var err error
x, y, err = convertToAbsolutePoint(ad, x, y) x, y, err = handlerDoubleTap(ad, x, y, opts...)
if err != nil { if err != nil {
return err return err
} }
actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y)
// adb shell input tap x y // adb shell input tap x y
xStr := fmt.Sprintf("%.1f", x) xStr := fmt.Sprintf("%.1f", x)

View File

@@ -256,12 +256,10 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("UIA2Driver.DoubleTap") log.Info().Float64("x", x).Float64("y", y).Msg("UIA2Driver.DoubleTap")
var err error var err error
x, y, err = convertToAbsolutePoint(ud, x, y) x, y, err = handlerDoubleTap(ud, x, y, opts...)
if err != nil { if err != nil {
return err return err
} }
actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y)
data := map[string]interface{}{ data := map[string]interface{}{
"actions": []interface{}{ "actions": []interface{}{

View File

@@ -541,11 +541,16 @@ func (wd *BrowserDriver) TapFloat(x, y float64, opts ...option.ActionOption) err
// DoubleTap Sends a double tap event at the coordinate. // DoubleTap Sends a double tap event at the coordinate.
func (wd *BrowserDriver) DoubleTap(x, y float64, options ...option.ActionOption) error { func (wd *BrowserDriver) DoubleTap(x, y float64, options ...option.ActionOption) error {
var err error
x, y, err = handlerDoubleTap(wd, x, y, options...)
if err != nil {
return err
}
data := map[string]interface{}{ data := map[string]interface{}{
"x": x, "x": x,
"y": y, "y": y,
} }
_, err := wd.HttpPOST(data, wd.sessionId, "ui/double_tap") _, err = wd.HttpPOST(data, wd.sessionId, "ui/double_tap")
return err return err
} }

View File

@@ -26,6 +26,27 @@ func handlerTapAbsXY(driver IDriver, rawX, rawY float64, opts ...option.ActionOp
return x, y, duration, nil return x, y, duration, nil
} }
func handlerDoubleTap(driver IDriver, rawX, rawY float64, opts ...option.ActionOption) (
x, y float64, err error) {
x, y, err = convertToAbsolutePoint(driver, rawX, rawY)
if err != nil {
return 0, 0, err
}
actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y)
// mark UI operation
if actionOptions.MarkOperationEnabled {
if markErr := MarkUIOperation(driver, ACTION_DoubleTapXY, []float64{x, y}); markErr != nil {
log.Warn().Err(markErr).Msg("Failed to mark double tap operation")
}
}
return x, y, nil
}
func handlerDrag(driver IDriver, rawFomX, rawFromY, rawToX, rawToY float64, opts ...option.ActionOption) ( func handlerDrag(driver IDriver, rawFomX, rawFromY, rawToX, rawToY float64, opts ...option.ActionOption) (
fromX, fromY, toX, toY float64, err error) { fromX, fromY, toX, toY float64, err error) {
@@ -59,7 +80,7 @@ func handlerSwipe(driver IDriver, rawFomX, rawFromY, rawToX, rawToY float64, opt
// mark UI operation // mark UI operation
if actionOptions.MarkOperationEnabled { if actionOptions.MarkOperationEnabled {
if markErr := MarkUIOperation(driver, ACTION_Swipe, []float64{fromX, fromY, toX, toY}); markErr != nil { if markErr := MarkUIOperation(driver, ACTION_Swipe, []float64{fromX, fromY, toX, toY}); markErr != nil {
log.Warn().Err(markErr).Msg("Failed to mark drag operation") log.Warn().Err(markErr).Msg("Failed to mark swipe operation")
} }
} }

View File

@@ -317,13 +317,13 @@ func MarkUIOperation(driver IDriver, actionType ActionMethod, actionCoordinates
timestamp := builtin.GenNameWithTimestamp("action_%d") timestamp := builtin.GenNameWithTimestamp("action_%d")
var imagePath string var imagePath string
if actionType == ACTION_TapAbsXY { if actionType == ACTION_TapAbsXY || actionType == ACTION_DoubleTapXY {
if len(actionCoordinates) != 2 { if len(actionCoordinates) != 2 {
return fmt.Errorf("invalid tap action coordinates: %v", actionCoordinates) return fmt.Errorf("invalid tap action coordinates: %v", actionCoordinates)
} }
imagePath = filepath.Join( imagePath = filepath.Join(
config.GetConfig().ScreenShotsPath, config.GetConfig().ScreenShotsPath,
fmt.Sprintf("%s_tap.png", timestamp), fmt.Sprintf("%s_%s.png", timestamp, actionType),
) )
x, y := actionCoordinates[0], actionCoordinates[1] x, y := actionCoordinates[0], actionCoordinates[1]
point := image.Point{X: int(x), Y: int(y)} point := image.Point{X: int(x), Y: int(y)}

View File

@@ -594,6 +594,9 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.TapAbsXY") log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.TapAbsXY")
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)] // [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
x = wd.toScale(x)
y = wd.toScale(y)
var err error var err error
x, y, _, err = handlerTapAbsXY(wd, x, y, opts...) x, y, _, err = handlerTapAbsXY(wd, x, y, opts...)
if err != nil { if err != nil {
@@ -601,8 +604,8 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
} }
data := map[string]interface{}{ data := map[string]interface{}{
"x": wd.toScale(x), "x": x,
"y": wd.toScale(y), "y": y,
} }
option.MergeOptions(data, opts...) option.MergeOptions(data, opts...)
@@ -614,16 +617,16 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error { func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.DoubleTap") log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.DoubleTap")
// [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)] // [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
x = wd.toScale(x)
y = wd.toScale(y)
var err error var err error
x, y, err = convertToAbsolutePoint(wd, x, y) x, y, err = handlerDoubleTap(wd, x, y, opts...)
if err != nil { if err != nil {
return err return err
} }
actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y)
x = wd.toScale(x)
y = wd.toScale(y)
data := map[string]interface{}{ data := map[string]interface{}{
"x": x, "x": x,
"y": y, "y": y,
@@ -648,23 +651,16 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
log.Info().Float64("fromX", fromX).Float64("fromY", fromY). log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("WDADriver.Drag") Float64("toX", toX).Float64("toY", toY).Msg("WDADriver.Drag")
// [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)] // [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)]
var err error
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(wd, fromX, fromY, toX, toY)
if err != nil {
return err
}
fromX = wd.toScale(fromX) fromX = wd.toScale(fromX)
fromY = wd.toScale(fromY) fromY = wd.toScale(fromY)
toX = wd.toScale(toX) toX = wd.toScale(toX)
toY = wd.toScale(toY) toY = wd.toScale(toY)
actionOptions := option.NewActionOptions(opts...)
fromX, fromY, toX, toY = actionOptions.ApplySwipeOffset(fromX, fromY, toX, toY)
// mark UI operation var err error
if actionOptions.MarkOperationEnabled { fromX, fromY, toX, toY, err = handlerDrag(wd, fromX, fromY, toX, toY, opts...)
if markErr := MarkUIOperation(wd, ACTION_Drag, []float64{fromX, fromY, toX, toY}); markErr != nil { if err != nil {
log.Warn().Err(markErr).Msg("Failed to mark drag operation") return err
}
} }
data := map[string]interface{}{ data := map[string]interface{}{