|
11 | 11 | from concurrent.futures import ThreadPoolExecutor |
12 | 12 | from functools import cached_property |
13 | 13 |
|
14 | | -from ok import BaseTask, Box, Logger, color_range_to_bound, run_in_new_thread, og, GenshinInteraction, PyDirectInteraction |
| 14 | +from ok import BaseTask, Box, Logger, color_range_to_bound, run_in_new_thread, og, GenshinInteraction, PyDirectInteraction, TaskDisabledException |
15 | 15 |
|
16 | 16 | logger = Logger.get_logger(__name__) |
17 | 17 | f_black_color = { |
@@ -183,10 +183,10 @@ def safe_get(self, key, default=None): |
183 | 183 | return default |
184 | 184 |
|
185 | 185 | def soundBeep(self, _n=None): |
186 | | - if hasattr(self, "config") and not self.config.get("发出声音提醒", True): |
| 186 | + if not self.afk_config.get("提示音", True): |
187 | 187 | return |
188 | 188 | if _n is None: |
189 | | - n = max(1, self.afk_config.get("提示音", 1)) |
| 189 | + n = max(1, self.afk_config.get("提示音次数", 1)) |
190 | 190 | else: |
191 | 191 | n = _n |
192 | 192 | run_in_new_thread( |
@@ -505,11 +505,22 @@ def move_mouse_relative(self, dx, dy, original_Xsensitivity=1.0, original_Ysensi |
505 | 505 | self.genshin_interaction.move_mouse_relative(int(dx), int(dy)) |
506 | 506 |
|
507 | 507 | def try_bring_to_front(self): |
508 | | - if not self.hwnd.is_foreground(): |
509 | | - win32api.keybd_event(win32con.VK_MENU, 0, 0, 0) |
510 | | - win32api.keybd_event(win32con.VK_MENU, 0, win32con.KEYEVENTF_KEYUP, 0) |
511 | | - self.hwnd.bring_to_front() |
512 | | - self.sleep(0.5) |
| 508 | + deadline = time.perf_counter() + 10 |
| 509 | + while time.perf_counter() < deadline: |
| 510 | + try: |
| 511 | + if not self.hwnd.is_foreground(): |
| 512 | + win32api.keybd_event(win32con.VK_MENU, 0, 0, 0) |
| 513 | + win32api.keybd_event(win32con.VK_MENU, 0, win32con.KEYEVENTF_KEYUP, 0) |
| 514 | + self.hwnd.bring_to_front() |
| 515 | + self.sleep(0.5) |
| 516 | + break |
| 517 | + except TaskDisabledException: |
| 518 | + raise |
| 519 | + except Exception as e: |
| 520 | + logger.error('try_bring_to_front error', e) |
| 521 | + self.sleep(1) |
| 522 | + else: |
| 523 | + raise Exception("Failed to bring window to front after multiple retries.") |
513 | 524 |
|
514 | 525 | track_point_color = { |
515 | 526 | "r": (121, 255), # Red range |
|
0 commit comments