@@ -330,8 +330,6 @@ def _handle_wait_during_idle(self, next_run: datetime) -> bool:
330330 strategy_map = {
331331 "close_game" : self ._wait_close_game ,
332332 "goto_main" : self ._wait_goto_main ,
333- "close_emulator_or_goto_main" : self ._wait_close_emulator_or_goto_main ,
334- "close_emulator_or_close_game" : self ._wait_close_emulator_or_close_game ,
335333 }
336334 func = strategy_map .get (method )
337335 if func is None :
@@ -376,9 +374,23 @@ def _wait_close_game(self, next_run: datetime) -> bool:
376374 logger .info ("Emulator is down, skip close_game/goto_main action and wait with preheat" )
377375 return self ._wait_until_with_emulator_preheat (next_run )
378376
379- close_game_limit_time = self .config .script .optimization .close_game_limit_time
380- close_game_limit = self ._time_to_timedelta (close_game_limit_time )
381- if close_game_limit > timedelta (0 ) and next_run > datetime .now () + close_game_limit :
377+ close_game_wait_duration = self .config .script .optimization .close_game_wait_duration
378+ close_game_wait = self ._time_to_timedelta (close_game_wait_duration )
379+ close_emulator_wait_duration = self .config .script .optimization .close_emulator_wait_duration
380+ close_emulator_wait = self ._time_to_timedelta (close_emulator_wait_duration )
381+
382+ if close_emulator_wait > timedelta (0 ) and next_run > datetime .now () + close_emulator_wait :
383+ logger .info ("Close emulator during wait" )
384+ self .device .emulator_stop ()
385+ self ._emulator_down = True
386+
387+ if not self ._wait_until_with_emulator_preheat (next_run ):
388+ return False
389+
390+ self .run ("Restart" )
391+ return True
392+
393+ if close_game_wait <= timedelta (0 ):
382394 logger .info ("Close game during wait" )
383395 self .device .app_stop ()
384396 self .device .release_during_wait ()
@@ -387,7 +399,16 @@ def _wait_close_game(self, next_run: datetime) -> bool:
387399 self .run ("Restart" )
388400 return True
389401
390- logger .info ("Wait without closing game (close_game limit time not reached)" )
402+ if next_run > datetime .now () + close_game_wait :
403+ logger .info ("Close game during wait" )
404+ self .device .app_stop ()
405+ self .device .release_during_wait ()
406+ if not self .wait_until (next_run ):
407+ return False
408+ self .run ("Restart" )
409+ return True
410+
411+ logger .info ("Wait without closing game (close_game wait duration not reached)" )
391412 self .device .release_during_wait ()
392413 if not self .wait_until (next_run ):
393414 return False
@@ -398,29 +419,11 @@ def _wait_goto_main(self, next_run: datetime) -> bool:
398419 logger .info ("Emulator is down, skip goto_main and wait with preheat" )
399420 return self ._wait_until_with_emulator_preheat (next_run )
400421
401- logger .info ("Goto main page during wait" )
402- self .run ("GotoMain" )
403- self .device .release_during_wait ()
404- return self .wait_until (next_run )
405-
406- def _wait_close_emulator_or_goto_main (self , next_run : datetime ) -> bool :
407- return self ._wait_close_emulator_or (next_run , self ._wait_goto_main )
408-
409- def _wait_close_emulator_or_close_game (self , next_run : datetime ) -> bool :
410- return self ._wait_close_emulator_or (next_run , self ._wait_close_game )
411-
412- def _wait_close_emulator_or (self , next_run : datetime , fallback_waiter : Callable [[datetime ], bool ]) -> bool :
413- close_emulator_limit_time = self .config .script .optimization .close_emulator_limit_time
414- close_emulator_limit = self ._time_to_timedelta (close_emulator_limit_time )
415-
416- now = datetime .now ()
417- if close_emulator_limit > timedelta (0 ) and next_run > now + close_emulator_limit :
422+ close_emulator_wait_duration = self .config .script .optimization .close_emulator_wait_duration
423+ close_emulator_wait = self ._time_to_timedelta (close_emulator_wait_duration )
424+ if close_emulator_wait > timedelta (0 ) and next_run > datetime .now () + close_emulator_wait :
418425 logger .info ("Close emulator during wait" )
419- if not self ._emulator_down :
420- self .device .emulator_stop ()
421- else :
422- logger .info ("Emulator already closed" )
423-
426+ self .device .emulator_stop ()
424427 self ._emulator_down = True
425428
426429 if not self ._wait_until_with_emulator_preheat (next_run ):
@@ -429,7 +432,10 @@ def _wait_close_emulator_or(self, next_run: datetime, fallback_waiter: Callable[
429432 self .run ("Restart" )
430433 return True
431434
432- return fallback_waiter (next_run )
435+ logger .info ("Goto main page during wait" )
436+ self .run ("GotoMain" )
437+ self .device .release_during_wait ()
438+ return self .wait_until (next_run )
433439
434440 def _wait_stay_there (self , next_run : datetime ) -> bool :
435441 if self ._emulator_down :
0 commit comments