From 3e7e9b0ef912336b6b18b9f2528421cb63c90726 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Mon, 17 Mar 2025 14:36:09 +0800 Subject: [PATCH] change: tap/swipe with offset --- internal/version/VERSION | 2 +- uixt/driver_ext_swipe.go | 2 +- uixt/driver_ext_test.go | 13 +++++++++++++ uixt/option/action.go | 17 +++++++++-------- uixt/option/screen.go | 5 +++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index d9a653d2..fe8b7add 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2503141055 +v5.0.0-beta-2503171436 diff --git a/uixt/driver_ext_swipe.go b/uixt/driver_ext_swipe.go index 9cb43574..78d1a532 100644 --- a/uixt/driver_ext_swipe.go +++ b/uixt/driver_ext_swipe.go @@ -156,7 +156,7 @@ func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) actionOptions := option.NewActionOptions(opts...) // tap app icon above the text - if len(actionOptions.Offset) == 0 { + if len(actionOptions.TapOffset) == 0 { opts = append(opts, option.WithTapOffset(0, -25)) } // set default swipe interval to 1 second diff --git a/uixt/driver_ext_test.go b/uixt/driver_ext_test.go index 9afdcd15..a50465ba 100644 --- a/uixt/driver_ext_test.go +++ b/uixt/driver_ext_test.go @@ -168,3 +168,16 @@ func TestDriverExt_ClosePopupsHandler(t *testing.T) { err := driver.ClosePopupsHandler() assert.Nil(t, err) } + +func TestDriverExt_Action_Risk(t *testing.T) { + driver := setupADBDriverExt(t) + + // tap point with offset + err := driver.TapXY(0.5, 0.5, option.WithTapOffset(-10, 10)) + assert.Nil(t, err) + + // swipe direction with offset + err = driver.Swipe(0.5, 0.5, 0.5, 0.9, + option.WithSwipeOffset(-50, 50, -50, 50)) + assert.Nil(t, err) +} diff --git a/uixt/option/action.go b/uixt/option/action.go index 594a6cd4..f2c5b0a0 100644 --- a/uixt/option/action.go +++ b/uixt/option/action.go @@ -95,13 +95,14 @@ func (o *ActionOptions) Options() []ActionOption { options = append(options, WithScope( o.Scope[0], o.Scope[1], o.Scope[2], o.Scope[3])) } - if len(o.Offset) == 2 { + if len(o.TapOffset) == 2 { // for tap [x,y] offset - options = append(options, WithTapOffset(o.Offset[0], o.Offset[1])) - } else if len(o.Offset) == 4 { + options = append(options, WithTapOffset(o.TapOffset[0], o.TapOffset[1])) + } + if len(o.SwipeOffset) == 4 { // for swipe [fromX, fromY, toX, toY] offset options = append(options, WithSwipeOffset( - o.Offset[0], o.Offset[1], o.Offset[2], o.Offset[3])) + o.SwipeOffset[0], o.SwipeOffset[1], o.SwipeOffset[2], o.SwipeOffset[3])) } if len(o.OffsetRandomRange) == 2 { options = append(options, WithOffsetRandomRange( @@ -132,9 +133,9 @@ func (o *ActionOptions) Options() []ActionOption { } func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) { - if len(o.Offset) == 2 { - absX += float64(o.Offset[0]) - absY += float64(o.Offset[1]) + if len(o.TapOffset) == 2 { + absX += float64(o.TapOffset[0]) + absY += float64(o.TapOffset[1]) } absX += o.GenerateRandomOffset() absY += o.GenerateRandomOffset() @@ -276,7 +277,7 @@ func WithCustomDirection(sx, sy, ex, ey float64) ActionOption { // swipe [fromX, fromY, toX, toY] with offset [offsetFromX, offsetFromY, offsetToX, offsetToY] func WithSwipeOffset(offsetFromX, offsetFromY, offsetToX, offsetToY int) ActionOption { return func(o *ActionOptions) { - o.Offset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY} + o.SwipeOffset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY} } } diff --git a/uixt/option/screen.go b/uixt/option/screen.go index 160dd4c9..01659f9c 100644 --- a/uixt/option/screen.go +++ b/uixt/option/screen.go @@ -216,7 +216,8 @@ type ScreenFilterOptions struct { AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"` Regex bool `json:"regex,omitempty" yaml:"regex,omitempty"` // use regex to match text - Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point + TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_offset,omitempty"` // tap with point offset + SwipeOffset []int `json:"swipe_offset,omitempty" yaml:"swipe_offset,omitempty"` // swipe with direction offset OffsetRandomRange []int `json:"offset_random_range,omitempty" yaml:"offset_random_range,omitempty"` // set random range [min, max] for tap/swipe points Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element MatchOne bool `json:"match_one,omitempty" yaml:"match_one,omitempty"` @@ -242,7 +243,7 @@ func WithAbsScope(x1, y1, x2, y2 int) ActionOption { // tap [x, y] with offset [offsetX, offsetY] func WithTapOffset(offsetX, offsetY int) ActionOption { return func(o *ActionOptions) { - o.Offset = []int{offsetX, offsetY} + o.TapOffset = []int{offsetX, offsetY} } }