Fix: Handle slow game startup and game died during startup (#61)

This commit is contained in:
LmeSzinc 2023-09-13 01:37:06 +08:00
parent d3eef2cd24
commit b29e95c1ea
8 changed files with 63 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -65,3 +65,13 @@ MONTHLY_CARD_REWARD = ButtonWrapper(
button=(741, 495, 1071, 644), button=(741, 495, 1071, 644),
), ),
) )
POPUP_SINGLE = ButtonWrapper(
name='POPUP_SINGLE',
share=Button(
file='./assets/share/base/popup/POPUP_SINGLE.png',
area=(602, 458, 626, 482),
search=(511, 365, 771, 575),
color=(95, 90, 77),
button=(578, 451, 705, 489),
),
)

View File

@ -47,3 +47,18 @@ class PopupHandler(ModuleBase):
return True return True
return False return False
def handle_popup_single(self, interval=2) -> bool:
"""
Popup with one single confirm button in the middle.
Args:
interval:
Returns:
If handled.
"""
if self.appear_then_click(POPUP_SINGLE, interval=interval):
return True
return False

View File

@ -13,6 +13,16 @@ LOGIN_CONFIRM = ButtonWrapper(
button=(683, 327, 1143, 620), button=(683, 327, 1143, 620),
), ),
) )
LOGIN_LOADING = ButtonWrapper(
name='LOGIN_LOADING',
share=Button(
file='./assets/share/login/LOGIN_LOADING.png',
area=(1103, 599, 1119, 616),
search=(1083, 579, 1139, 636),
color=(98, 98, 106),
button=(1103, 599, 1119, 616),
),
)
USER_AGREEMENT_ACCEPT = ButtonWrapper( USER_AGREEMENT_ACCEPT = ButtonWrapper(
name='USER_AGREEMENT_ACCEPT', name='USER_AGREEMENT_ACCEPT',
cn=Button( cn=Button(

View File

@ -1,8 +1,9 @@
from module.base.timer import Timer from module.base.timer import Timer
from module.exception import GameNotRunningError
from module.logger import logger from module.logger import logger
from tasks.base.page import page_main from tasks.base.page import page_main
from tasks.base.ui import UI from tasks.base.ui import UI
from tasks.login.assets.assets_login import LOGIN_CONFIRM, USER_AGREEMENT_ACCEPT from tasks.login.assets.assets_login import LOGIN_CONFIRM, USER_AGREEMENT_ACCEPT, LOGIN_LOADING
class Login(UI): class Login(UI):
@ -15,13 +16,21 @@ class Login(UI):
Raises: Raises:
GameStuckError: GameStuckError:
GameTooManyClickError: GameTooManyClickError:
GameNotRunningError:
""" """
logger.hr('App login') logger.hr('App login')
orientation_timer = Timer(5) orientation_timer = Timer(5)
startup_timer = Timer(5).start()
app_timer = Timer(5).start()
login_success = False login_success = False
while 1: while 1:
# Watch if game alive
if app_timer.reached():
if not self.device.app_is_running():
logger.error('Game died during launch')
raise GameNotRunningError('Game not running')
app_timer.reset()
# Watch device rotation # Watch device rotation
if not login_success and orientation_timer.reached(): if not login_success and orientation_timer.reached():
# Screen may rotate after starting an app # Screen may rotate after starting an app
@ -31,27 +40,41 @@ class Login(UI):
self.device.screenshot() self.device.screenshot()
# End # End
if self.ui_page_appear(page_main): # Game client requires at least 5s to start
logger.info('Login to main confirm') # The first few frames might be captured before app_stop(), ignore them
break if startup_timer.reached():
if self.ui_page_appear(page_main):
logger.info('Login to main confirm')
break
# Watch resource downloading and loading
if self.appear(LOGIN_LOADING, interval=5):
logger.info('Game resources downloading or loading')
self.device.stuck_record_clear()
# Login # Login
if self.appear_then_click(LOGIN_CONFIRM): if self.appear_then_click(LOGIN_CONFIRM):
login_success = True
continue continue
if self.appear_then_click(USER_AGREEMENT_ACCEPT): if self.appear_then_click(USER_AGREEMENT_ACCEPT):
continue continue
# Additional # Additional
if self.handle_popup_single():
continue
if self.ui_additional(): if self.ui_additional():
continue continue
return True return True
def handle_app_login(self): def handle_app_login(self):
logger.info('handle_app_login')
self.device.screenshot_interval_set(1.0) self.device.screenshot_interval_set(1.0)
self.device.stuck_timer = Timer(300, count=300).start()
try: try:
self._handle_app_login() self._handle_app_login()
finally: finally:
self.device.screenshot_interval_set() self.device.screenshot_interval_set()
self.device.stuck_timer = Timer(60, count=60).start()
def app_stop(self): def app_stop(self):
logger.hr('App stop') logger.hr('App stop')