refactor: use WithRelative to set relative coordinate, absolute by default

This commit is contained in:
lilong.129
2025-03-03 20:09:24 +08:00
parent 81a9562ffe
commit 359199a485
10 changed files with 51 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ type ActionOptions struct {
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty"`
AbsCoordinate bool `json:"abs,omitempty" yaml:"abs,omitempty"` // use absolute coordinate
Relative bool `json:"relative,omitempty" yaml:"relative,omitempty"` // use relative coordinate
ScreenOptions
@@ -56,8 +56,8 @@ func (o *ActionOptions) Options() []ActionOption {
if o.Steps != 0 {
options = append(options, WithSteps(o.Steps))
}
if o.AbsCoordinate {
options = append(options, WithAbsoluteCoordinate(true))
if o.Relative {
options = append(options, WithRelative(true))
}
switch v := o.Direction.(type) {
@@ -260,9 +260,10 @@ func WithDirection(direction string) ActionOption {
}
}
func WithAbsoluteCoordinate(abs bool) ActionOption {
// WithRelative set relative coordinate, (0, 0) is the top-left corner of the screen
func WithRelative(relative bool) ActionOption {
return func(o *ActionOptions) {
o.AbsCoordinate = abs
o.Relative = relative
}
}