Fix: Lang check failed due to popup

This commit is contained in:
LmeSzinc 2023-12-08 22:00:11 +08:00
parent fcb81bde46
commit 6acd64a1f4
2 changed files with 13 additions and 1 deletions

View File

@ -64,6 +64,7 @@ class MainPage(PopupHandler):
plane: MapPlane = KEYWORDS_MAP_PLANE.Herta_ParlorCar plane: MapPlane = KEYWORDS_MAP_PLANE.Herta_ParlorCar
_lang_checked = False _lang_checked = False
_lang_check_success = True
def update_plane(self, lang=None) -> MapPlane | None: def update_plane(self, lang=None) -> MapPlane | None:
""" """
@ -108,6 +109,8 @@ class MainPage(PopupHandler):
if lang_unknown or lang != server.lang: if lang_unknown or lang != server.lang:
self.config.Emulator_GameLanguage = lang self.config.Emulator_GameLanguage = lang
server.set_lang(lang) server.set_lang(lang)
MainPage._lang_checked = True
MainPage._lang_check_success = True
return lang return lang
if lang_unknown: if lang_unknown:
@ -115,6 +118,8 @@ class MainPage(PopupHandler):
raise RequestHumanTakeover raise RequestHumanTakeover
else: else:
logger.warning(f'Cannot detect in-game text language, assume current lang={server.lang} is correct') logger.warning(f'Cannot detect in-game text language, assume current lang={server.lang} is correct')
MainPage._lang_checked = True
MainPage._lang_check_success = False
return server.lang return server.lang
def handle_lang_check(self, page: Page): def handle_lang_check(self, page: Page):
@ -131,7 +136,6 @@ class MainPage(PopupHandler):
return False return False
self.check_lang_from_map_plane() self.check_lang_from_map_plane()
MainPage._lang_checked = True
return True return True
def acquire_lang_checked(self): def acquire_lang_checked(self):

View File

@ -72,8 +72,16 @@ class PopupHandler(ModuleBase):
If handled. If handled.
""" """
if self.appear_then_click(MONTHLY_CARD_REWARD, interval=interval): if self.appear_then_click(MONTHLY_CARD_REWARD, interval=interval):
# Language check at the first login of the day may fail due to popups
# Retry later
from tasks.base.main_page import MainPage
if not MainPage._lang_check_success:
MainPage._lang_checked = False
return True return True
if self.appear_then_click(MONTHLY_CARD_GET_ITEM, interval=interval): if self.appear_then_click(MONTHLY_CARD_GET_ITEM, interval=interval):
from tasks.base.main_page import MainPage
if not MainPage._lang_check_success:
MainPage._lang_checked = False
return True return True
return False return False