From 71dac459e673eda402022dff6b135f1bcdf0d2a3 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Tue, 6 May 2025 00:52:47 +0800 Subject: [PATCH] refactor: handlerDoubleTap --- internal/version/VERSION | 2 +- uixt/android_driver_adb.go | 4 +--- uixt/android_driver_uia2.go | 4 +--- uixt/browser_driver.go | 7 ++++++- uixt/driver_ext_handler.go | 23 ++++++++++++++++++++++- uixt/driver_ext_screenshot.go | 4 ++-- uixt/ios_driver_wda.go | 34 +++++++++++++++------------------- 7 files changed, 48 insertions(+), 30 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index 0d77f6e8..c72bd90a 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2505060041 +v5.0.0-beta-2505060055 diff --git a/uixt/android_driver_adb.go b/uixt/android_driver_adb.go index 589296fb..7565a066 100644 --- a/uixt/android_driver_adb.go +++ b/uixt/android_driver_adb.go @@ -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 { log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.DoubleTap") var err error - x, y, err = convertToAbsolutePoint(ad, x, y) + x, y, err = handlerDoubleTap(ad, x, y, opts...) if err != nil { return err } - actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyTapOffset(x, y) // adb shell input tap x y xStr := fmt.Sprintf("%.1f", x) diff --git a/uixt/android_driver_uia2.go b/uixt/android_driver_uia2.go index e3b46751..012e04ef 100644 --- a/uixt/android_driver_uia2.go +++ b/uixt/android_driver_uia2.go @@ -256,12 +256,10 @@ 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 = convertToAbsolutePoint(ud, x, y) + x, y, err = handlerDoubleTap(ud, x, y, opts...) if err != nil { return err } - actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyTapOffset(x, y) data := map[string]interface{}{ "actions": []interface{}{ diff --git a/uixt/browser_driver.go b/uixt/browser_driver.go index cb708f8c..1e560639 100644 --- a/uixt/browser_driver.go +++ b/uixt/browser_driver.go @@ -541,11 +541,16 @@ 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...) + if err != nil { + return err + } data := map[string]interface{}{ "x": x, "y": y, } - _, err := wd.HttpPOST(data, wd.sessionId, "ui/double_tap") + _, err = wd.HttpPOST(data, wd.sessionId, "ui/double_tap") return err } diff --git a/uixt/driver_ext_handler.go b/uixt/driver_ext_handler.go index 09b8d9a1..fcc45a6a 100644 --- a/uixt/driver_ext_handler.go +++ b/uixt/driver_ext_handler.go @@ -26,6 +26,27 @@ func handlerTapAbsXY(driver IDriver, rawX, rawY float64, opts ...option.ActionOp 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) ( fromX, fromY, toX, toY float64, err error) { @@ -59,7 +80,7 @@ func handlerSwipe(driver IDriver, rawFomX, rawFromY, rawToX, rawToY float64, opt // mark UI operation if actionOptions.MarkOperationEnabled { 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") } } diff --git a/uixt/driver_ext_screenshot.go b/uixt/driver_ext_screenshot.go index 33028bc6..fa10851b 100644 --- a/uixt/driver_ext_screenshot.go +++ b/uixt/driver_ext_screenshot.go @@ -317,13 +317,13 @@ func MarkUIOperation(driver IDriver, actionType ActionMethod, actionCoordinates timestamp := builtin.GenNameWithTimestamp("action_%d") var imagePath string - if actionType == ACTION_TapAbsXY { + if actionType == ACTION_TapAbsXY || actionType == ACTION_DoubleTapXY { if len(actionCoordinates) != 2 { return fmt.Errorf("invalid tap action coordinates: %v", actionCoordinates) } imagePath = filepath.Join( config.GetConfig().ScreenShotsPath, - fmt.Sprintf("%s_tap.png", timestamp), + fmt.Sprintf("%s_%s.png", timestamp, actionType), ) x, y := actionCoordinates[0], actionCoordinates[1] point := image.Point{X: int(x), Y: int(y)} diff --git a/uixt/ios_driver_wda.go b/uixt/ios_driver_wda.go index e5865632..4cbd8e1d 100644 --- a/uixt/ios_driver_wda.go +++ b/uixt/ios_driver_wda.go @@ -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") // [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)] + x = wd.toScale(x) + y = wd.toScale(y) + var err error x, y, _, err = handlerTapAbsXY(wd, x, y, opts...) if err != nil { @@ -601,8 +604,8 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { } data := map[string]interface{}{ - "x": wd.toScale(x), - "y": wd.toScale(y), + "x": x, + "y": y, } 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 { log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.DoubleTap") // [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)] + + x = wd.toScale(x) + y = wd.toScale(y) + var err error - x, y, err = convertToAbsolutePoint(wd, x, y) + x, y, err = handlerDoubleTap(wd, x, y, opts...) if err != nil { return err } - actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyTapOffset(x, y) - x = wd.toScale(x) - y = wd.toScale(y) data := map[string]interface{}{ "x": x, "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). Float64("toX", toX).Float64("toY", toY).Msg("WDADriver.Drag") // [[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) fromY = wd.toScale(fromY) toX = wd.toScale(toX) toY = wd.toScale(toY) - actionOptions := option.NewActionOptions(opts...) - fromX, fromY, toX, toY = actionOptions.ApplySwipeOffset(fromX, fromY, toX, toY) - // mark UI operation - if actionOptions.MarkOperationEnabled { - if markErr := MarkUIOperation(wd, ACTION_Drag, []float64{fromX, fromY, toX, toY}); markErr != nil { - log.Warn().Err(markErr).Msg("Failed to mark drag operation") - } + var err error + fromX, fromY, toX, toY, err = handlerDrag(wd, fromX, fromY, toX, toY, opts...) + if err != nil { + return err } data := map[string]interface{}{