From 4ec00be8b9c08fe74c249930496e555b13a3e40c Mon Sep 17 00:00:00 2001 From: Hommy <16620803786@163.com> Date: Thu, 26 Feb 2026 21:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=A8=8B=E5=BA=8F=E5=A4=B1?= =?UTF-8?q?=E5=8E=BB=E7=84=A6=E7=82=B9=E5=AF=BC=E8=87=B4=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pyJianYingDraft/jianying_controller.py | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/pyJianYingDraft/jianying_controller.py b/src/pyJianYingDraft/jianying_controller.py index 6a51714..b4f69e8 100644 --- a/src/pyJianYingDraft/jianying_controller.py +++ b/src/pyJianYingDraft/jianying_controller.py @@ -187,6 +187,23 @@ class JianyingController: export_btn.Click(simulateMove=False) time.sleep(5) + def __ensure_window_focus(self) -> None: + """在点击前确保窗口有焦点""" + # 1. 确保窗口激活 + self.app.SetActive() + time.sleep(1) + + # 2. 确保窗口置顶 + self.app.SetTopmost() + time.sleep(1) + + # 3. 强制获取焦点 + try: + self.app.SetFocus() + except: + pass # 某些情况下可能失败,但继续执行 + time.sleep(1) + def wait_for_export_completion(self, timeout: float) -> None: """等待导出完成 @@ -255,7 +272,9 @@ class JianyingController: original_path = None - for i in range(64): + for i in range(16): + # 确保窗口有焦点 + self.__ensure_window_focus() if self.app_status == "home": logger.info("[%d]app is already in home page", i) self.find_and_click_draft(draft_name) @@ -295,7 +314,7 @@ class JianyingController: def switch_to_home(self) -> None: """切换到剪映主页""" - for i in range(32): + for i in range(8): if self.app_status == "home": return elif self.app_status == "pre_export":