Просмотр исходного кода

fix(script):修复 _wait_close_game 日志误导及优化 datetime.now() 调用

- 修复 _wait_close_game 中的误导性日志消息,使其与实际行为(未调用 GotoMain)一致
- 优化 _wait_until_with_emulator_preheat 和 _wait_close_emulator_or 中的 datetime.now() 调用,
  预先捕获时间以避免轻微的竞态条件并提高阈值比较的可读性
yuyuyuyuyu 6 месяцев назад
Родитель
Сommit
3bbf105773
1 измененных файлов с 8 добавлено и 5 удалено
  1. 8 5
      script.py

+ 8 - 5
script.py

@@ -351,11 +351,13 @@ class Script:
             return self.wait_until(next_run)
 
         startup_lead = self._time_to_timedelta(self.config.script.optimization.emulator_startup_lead_time)
+        now = datetime.now()
         wake_time = next_run - startup_lead if startup_lead > timedelta(0) else next_run
-        if wake_time < datetime.now():
-            wake_time = datetime.now()
+        if wake_time < now:
+            wake_time = now
 
-        if wake_time > datetime.now():
+        now = datetime.now()
+        if wake_time > now:
             logger.info(f"Wait before wake emulator: {wake_time.strftime('%Y-%m-%d %H:%M:%S')}")
             if not self.wait_until(wake_time):
                 return False
@@ -385,7 +387,7 @@ class Script:
             self.run("Restart")
             return True
 
-        logger.info("Goto main page during wait (close_game limit time not reached)")
+        logger.info("Wait without closing game (close_game limit time not reached)")
         self.device.release_during_wait()
         if not self.wait_until(next_run):
             return False
@@ -411,7 +413,8 @@ class Script:
         close_emulator_limit_time = self.config.script.optimization.close_emulator_limit_time
         close_emulator_limit = self._time_to_timedelta(close_emulator_limit_time)
 
-        if close_emulator_limit > timedelta(0) and next_run > datetime.now() + close_emulator_limit:
+        now = datetime.now()
+        if close_emulator_limit > timedelta(0) and next_run > now + close_emulator_limit:
             logger.info("Close emulator during wait")
             if not self._emulator_down:
                 self.device.emulator_stop()