diff --git a/module/device/device.py b/module/device/device.py index 7f7bf27..4dbcb73 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -186,3 +186,6 @@ class Device(Screenshot, Control, AppControl, Platform): super().app_stop() self.stuck_record_clear() self.click_record_clear() + + def back(self): + self.u2.press("back") \ No newline at end of file diff --git a/tasks/base/ui.py b/tasks/base/ui.py index e39ce3c..d9cf84f 100644 --- a/tasks/base/ui.py +++ b/tasks/base/ui.py @@ -98,7 +98,7 @@ class UI(MainPage): continue logger.info("Unknown page, try to back") if u2_back: - self.device.u2.press("back") + self.device.back() u2_back = False else: self.device.click(BACK) @@ -178,7 +178,11 @@ class UI(MainPage): continue if back_timer.reached_and_reset(): - self.device.u2.press("back") + if self.match_color(LOGIN_LOADING, interval=5, threshold=80) or self.appear_trademark_year(): + from tasks.login.login import Login + Login(self.config, self.device).handle_app_login() + continue + self.device.back() logger.info("Unknown page, try to back") # Reset connection @@ -439,7 +443,7 @@ class UI(MainPage): self.device.screenshot() if self.match_color(check_button): break - self.device.u2.press("back") + self.device.back() if timer.reached(): logger.error("Failed to close popup") raise RequestHumanTakeover diff --git a/tasks/login/login.py b/tasks/login/login.py index ef7bb9f..a9d602a 100644 --- a/tasks/login/login.py +++ b/tasks/login/login.py @@ -1,11 +1,9 @@ from module.base.timer import Timer -from module.base.decorator import Config -from module.ocr.ocr import Digit from module.exception import GameNotRunningError from module.logger import logger from tasks.base.page import page_main from tasks.base.ui import UI -from tasks.login.assets.assets_login import LOGIN_CONFIRM, LOGIN_LOADING, UPDATE, SURVEY, OCR_YEAR +from tasks.login.assets.assets_login import LOGIN_CONFIRM, LOGIN_LOADING, UPDATE class Login(UI): @@ -31,20 +29,11 @@ class Login(UI): return True return False - @Config.when(Emulator_GameLanguage='en') - def _handle_survey(self): - if self.appear_then_click(SURVEY): - return True - return False - - @Config.when(Emulator_GameLanguage=None) - def _handle_survey(self): - pass - logger.hr('App login') orientation_timer = Timer(5) startup_timer = Timer(5).start() app_timer = Timer(5).start() + back_timer = Timer(2).start() login_success = False while 1: @@ -73,10 +62,11 @@ class Login(UI): break # Watch resource downloading and loading + loading = False if self.match_color(LOGIN_LOADING, interval=5, threshold=45): logger.info('Game resources downloading or loading') self.device.stuck_record_clear() - + loading = True # Login if self.appear_then_click(LOGIN_CONFIRM): login_success = True @@ -90,12 +80,10 @@ class Login(UI): # continue if self.appear_then_click(UPDATE): continue - if _handle_survey(self): - continue if self.ui_additional(): continue - if not self.appear_trademark_year(): - self.device.u2.press("back") + if not loading and back_timer.reached_and_reset() and not self.appear_trademark_year(): + self.device.back() return True