diff --git a/internal/version/VERSION b/internal/version/VERSION index 6a4c76d1..174a2016 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2505092330 +v5.0.0-beta-2505100001 diff --git a/step_ui.go b/step_ui.go index 185bbb59..3a723c87 100644 --- a/step_ui.go +++ b/step_ui.go @@ -91,18 +91,20 @@ func (s *StepMobile) WebLoginNoneUI(packageName, phoneNumber string, captcha, pa return s } -func (s *StepMobile) AppLaunch(bundleId string) *StepMobile { +func (s *StepMobile) AppLaunch(bundleId string, opts ...option.ActionOption) *StepMobile { s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{ - Method: uixt.ACTION_AppLaunch, - Params: bundleId, + Method: uixt.ACTION_AppLaunch, + Params: bundleId, + Options: option.NewActionOptions(opts...), }) return s } -func (s *StepMobile) AppTerminate(bundleId string) *StepMobile { +func (s *StepMobile) AppTerminate(bundleId string, opts ...option.ActionOption) *StepMobile { s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{ - Method: uixt.ACTION_AppTerminate, - Params: bundleId, + Method: uixt.ACTION_AppTerminate, + Params: bundleId, + Options: option.NewActionOptions(opts...), }) return s } diff --git a/uixt/driver_action.go b/uixt/driver_action.go index 2a28a5d0..419258da 100644 --- a/uixt/driver_action.go +++ b/uixt/driver_action.go @@ -145,13 +145,13 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) { } case ACTION_AppClear: if packageName, ok := action.Params.(string); ok { - if err = dExt.AppClear(packageName); err != nil { + if err = dExt.AppClear(packageName, action.GetOptions()...); err != nil { return errors.Wrap(err, "failed to clear app") } } case ACTION_AppLaunch: if bundleId, ok := action.Params.(string); ok { - return dExt.AppLaunch(bundleId) + return dExt.AppLaunch(bundleId, action.GetOptions()...) } return fmt.Errorf("invalid %s params, should be bundleId(string), got %v", ACTION_AppLaunch, action.Params) @@ -177,7 +177,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) { return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params) case ACTION_AppTerminate: if bundleId, ok := action.Params.(string); ok { - success, err := dExt.AppTerminate(bundleId) + success, err := dExt.AppTerminate(bundleId, action.GetOptions()...) if err != nil { return errors.Wrap(err, "failed to terminate app") } diff --git a/uixt/option/action.go b/uixt/option/action.go index b8ad41a1..b826c8f0 100644 --- a/uixt/option/action.go +++ b/uixt/option/action.go @@ -134,6 +134,7 @@ 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 } diff --git a/uixt/option/hook.go b/uixt/option/hook.go index 54fbb55a..365bed75 100644 --- a/uixt/option/hook.go +++ b/uixt/option/hook.go @@ -8,6 +8,22 @@ type HookOptions struct { 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) {