feat: add pre hook and post hook for DoubleTap action

This commit is contained in:
lilong.129
2025-05-09 23:06:45 +08:00
parent 3715cbb432
commit f7ec4a06b4
6 changed files with 21 additions and 13 deletions

View File

@@ -326,11 +326,12 @@ func (ad *ADBDriver) TapAbsXY(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")
var err error
x, y, err = handlerDoubleTap(ad, x, y, opts...)
actionOptions := option.NewActionOptions(opts...)
x, y, err := preHandler_DoubleTap(ad, actionOptions, x, y)
if err != nil {
return err
}
defer postHandler(ad, actionOptions)
// adb shell input tap x y
xStr := fmt.Sprintf("%.1f", x)

View File

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

View File

@@ -535,11 +535,13 @@ func (wd *BrowserDriver) TapFloat(x, y float64, opts ...option.ActionOption) err
// DoubleTap Sends a double tap event at the coordinate.
func (wd *BrowserDriver) DoubleTap(x, y float64, options ...option.ActionOption) error {
var err error
x, y, err = handlerDoubleTap(wd, x, y, options...)
actionOptions := option.NewActionOptions(options...)
x, y, err := preHandler_DoubleTap(wd, actionOptions, x, y)
if err != nil {
return err
}
defer postHandler(wd, actionOptions)
data := map[string]interface{}{
"x": x,
"y": y,

View File

@@ -24,19 +24,22 @@ func preHandler_TapAbsXY(driver IDriver, options *option.ActionOptions, rawX, ra
return x, y, nil
}
func handlerDoubleTap(driver IDriver, rawX, rawY float64, opts ...option.ActionOption) (
func preHandler_DoubleTap(driver IDriver, options *option.ActionOptions, rawX, rawY float64) (
x, y float64, err error) {
if options.PreHook != nil {
options.PreHook()
}
x, y, err = convertToAbsolutePoint(driver, rawX, rawY)
if err != nil {
return 0, 0, err
}
actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y)
x, y = options.ApplyTapOffset(x, y)
// mark UI operation
if actionOptions.MarkOperationEnabled {
if options.MarkOperationEnabled {
if markErr := MarkUIOperation(driver, ACTION_DoubleTapXY, []float64{x, y}); markErr != nil {
log.Warn().Err(markErr).Msg("Failed to mark double tap operation")
}

View File

@@ -622,11 +622,12 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
x = wd.toScale(x)
y = wd.toScale(y)
var err error
x, y, err = handlerDoubleTap(wd, x, y, opts...)
actionOptions := option.NewActionOptions(opts...)
x, y, err := preHandler_DoubleTap(wd, actionOptions, x, y)
if err != nil {
return err
}
defer postHandler(wd, actionOptions)
data := map[string]interface{}{
"x": x,