feat: add WithPreMarkOperation and WithPostMarkOperation to mark UI operation before/after action

This commit is contained in:
lilong.129
2025-05-12 08:58:27 +08:00
parent 7a6890a160
commit d95eec78b0
7 changed files with 33 additions and 109 deletions

View File

@@ -23,7 +23,6 @@ type ActionOptions struct {
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty"`
ScreenOptions
HookOptions
// set custiom options such as textview, id, description
Custom map[string]interface{} `json:"custom,omitempty" yaml:"custom,omitempty"`
@@ -134,7 +133,6 @@ func (o *ActionOptions) Options() []ActionOption {
options = append(options, o.GetScreenShotOptions()...)
options = append(options, o.GetScreenRecordOptions()...)
options = append(options, o.GetMarkOperationOptions()...)
options = append(options, o.GetHookOptions()...)
return options
}

View File

@@ -1,47 +0,0 @@
package option
// HookOptions contains options for action hooks
type HookOptions struct {
// pre hook before action
PreHook func()
// post hook after action
PostHook func()
}
func (o *HookOptions) GetHookOptions() []ActionOption {
options := make([]ActionOption, 0)
if o == nil {
return options
}
if o.PreHook != nil {
options = append(options, WithPreHook(o.PreHook))
}
if o.PostHook != nil {
options = append(options, WithPostHook(o.PostHook))
}
return options
}
// WithPreHook sets the pre hook before action
func WithPreHook(preHook func()) ActionOption {
return func(o *ActionOptions) {
o.PreHook = preHook
}
}
// WithPostHook sets the post hook after action
func WithPostHook(postHook func()) ActionOption {
return func(o *ActionOptions) {
o.PostHook = postHook
}
}
// WithHooks sets the pre hook and post hook
func WithHooks(preHook func(), postHook func()) ActionOption {
return func(o *ActionOptions) {
o.PreHook = preHook
o.PostHook = postHook
}
}

View File

@@ -277,8 +277,8 @@ func WithIndex(index int) ActionOption {
// MarkOperationOptions contains options for marking UI operations
type MarkOperationOptions struct {
// mark UI operation, enable/disable UI operation marking
MarkOperationEnabled bool `json:"mark_operation_enabled,omitempty" yaml:"mark_operation_enabled,omitempty"`
PreMarkOperation bool `json:"pre_mark_operation,omitempty" yaml:"pre_mark_operation,omitempty"`
PostMarkOperation bool `json:"post_mark_operation,omitempty" yaml:"post_mark_operation,omitempty"`
}
func (o *MarkOperationOptions) GetMarkOperationOptions() []ActionOption {
@@ -287,16 +287,26 @@ func (o *MarkOperationOptions) GetMarkOperationOptions() []ActionOption {
return options
}
if o.MarkOperationEnabled {
options = append(options, WithMarkOperationEnabled(true))
if o.PreMarkOperation {
options = append(options, WithPreMarkOperation(true))
}
if o.PostMarkOperation {
options = append(options, WithPostMarkOperation(true))
}
return options
}
// WithMarkOperationEnabled enables or disables UI operation marking
func WithMarkOperationEnabled(enabled bool) ActionOption {
// WithPreMarkOperation enables UI operation marking before action
func WithPreMarkOperation(enabled bool) ActionOption {
return func(o *ActionOptions) {
o.MarkOperationEnabled = enabled
o.PreMarkOperation = enabled
}
}
// WithPostMarkOperation enables UI operation marking after action
func WithPostMarkOperation(enabled bool) ActionOption {
return func(o *ActionOptions) {
o.PostMarkOperation = enabled
}
}