refactor: device Install interface

This commit is contained in:
lilong.129
2024-10-23 21:02:06 +08:00
parent 4b568dac01
commit b8083cd03e
10 changed files with 51 additions and 29 deletions
+21 -11
View File
@@ -15,7 +15,7 @@ type InstallOptions struct {
Reinstall bool
GrantPermission bool
Downgrade bool
RetryTime int
RetryTimes int
}
type InstallOption func(o *InstallOptions)
@@ -46,9 +46,9 @@ func WithDowngrade(downgrade bool) InstallOption {
}
}
func WithRetryTime(retryTime int) InstallOption {
func WithRetryTimes(retryTimes int) InstallOption {
return func(o *InstallOptions) {
o.RetryTime = retryTime
o.RetryTimes = retryTimes
}
}
@@ -58,7 +58,7 @@ type InstallResult struct {
ErrorMsg string `json:"errorMsg"`
}
func (dExt *DriverExt) InstallByUrl(url string, opts *InstallOptions) error {
func (dExt *DriverExt) InstallByUrl(url string, options ...InstallOption) error {
// 获取当前目录
cwd, err := os.Getwd()
if err != nil {
@@ -73,7 +73,7 @@ func (dExt *DriverExt) InstallByUrl(url string, opts *InstallOptions) error {
return err
}
err = dExt.Install(appPath, opts)
err = dExt.Install(appPath, options...)
if err != nil {
log.Error().Err(err).Msg("install app failed")
return err
@@ -81,7 +81,7 @@ func (dExt *DriverExt) InstallByUrl(url string, opts *InstallOptions) error {
return nil
}
func (dExt *DriverExt) Install(filePath string, opts *InstallOptions) error {
func (dExt *DriverExt) Install(filePath string, options ...InstallOption) error {
if _, ok := dExt.Device.(*AndroidDevice); ok {
stopChan := make(chan struct{})
go func() {
@@ -92,13 +92,23 @@ func (dExt *DriverExt) Install(filePath string, opts *InstallOptions) error {
select {
case <-ticker.C:
actions := []TapTextAction{
{Text: "^.*无视风险安装$", Options: []ActionOption{WithTapOffset(100, 0), WithRegex(true), WithIgnoreNotFoundError(true)}},
{Text: "^已了解此应用未经检测.*", Options: []ActionOption{WithTapOffset(-450, 0), WithRegex(true), WithIgnoreNotFoundError(true)}},
{
Text: "^.*无视风险安装$",
Options: []ActionOption{WithTapOffset(100, 0), WithRegex(true), WithIgnoreNotFoundError(true)},
},
{
Text: "^已了解此应用未经检测.*",
Options: []ActionOption{WithTapOffset(-450, 0), WithRegex(true), WithIgnoreNotFoundError(true)},
},
}
_ = dExt.Driver.TapByTexts(actions...)
_ = dExt.TapByOCR("^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|安装|授权本次安装|继续安装|重新安装)$", WithRegex(true), WithIgnoreNotFoundError(true))
_ = dExt.TapByOCR(
"^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|安装|授权本次安装|继续安装|重新安装)$",
WithRegex(true), WithIgnoreNotFoundError(true),
)
case <-stopChan:
fmt.Println("Ticker stopped")
log.Info().Msg("Ticker stopped")
return
}
}
@@ -108,7 +118,7 @@ func (dExt *DriverExt) Install(filePath string, opts *InstallOptions) error {
}()
}
return dExt.Device.Install(filePath, opts)
return dExt.Device.Install(filePath, options...)
}
func (dExt *DriverExt) Uninstall(packageName string, options ...ActionOption) error {