feat: add auto popup handler

This commit is contained in:
lilong.129
2023-04-28 22:23:50 +08:00
parent 68dc545f35
commit 824fbe393d
+32 -3
View File
@@ -45,6 +45,7 @@ var androidActivities = map[string]map[string]string{
"feed": "com.yxcorp.gifshow.HomeActivity", "feed": "com.yxcorp.gifshow.HomeActivity",
"live": "com.kuaishou.live.core.basic.activity.LiveSlideActivity", "live": "com.kuaishou.live.core.basic.activity.LiveSlideActivity",
}, },
// TODO: SPH, XHS
} }
type LiveCrawler struct { type LiveCrawler struct {
@@ -111,6 +112,12 @@ func (l *LiveCrawler) exitLiveRoom() error {
return nil return nil
} }
} }
// exit live room failed, while video count achieved
if l.currentStat.IsTargetAchieved(&l.configs.TargetCount) {
return nil
}
return errors.New("exit live room failed") return errors.New("exit live room failed")
} }
@@ -203,9 +210,31 @@ func (dExt *DriverExt) assertActivity(pacakgeName, activityType string) error {
return fmt.Errorf("%s activity is not in foreground", activityType) return fmt.Errorf("%s activity is not in foreground", activityType)
} }
func (dExt *DriverExt) autoPopupHandler(texts OCRTexts) error { // TODO: add more popup texts
texts.FindTexts([]string{"确定", "取消"}) var popups = [][]string{
{"青少年", "我知道了"}, // 青少年弹窗
{"允许", "拒绝"},
{"确定", "取消"},
}
// log.Warn().Msg("text popup found") func (dExt *DriverExt) autoPopupHandler(texts OCRTexts) error {
for _, popup := range popups {
if len(popup) != 2 {
continue
}
points, err := texts.FindTexts([]string{"确定", "取消"})
if err == nil {
log.Warn().Msg("text popup found")
if err := dExt.TapAbsXY(points[1].X, points[1].Y); err != nil {
log.Error().Err(err).Msg("tap popup failed")
return err
}
// tap popup success
return nil
}
}
// no popup found
return nil return nil
} }