From d45da439bd2b0edf820c1ec1ca810bfeec2fa9b6 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Wed, 12 Feb 2025 22:15:17 +0800 Subject: [PATCH] =?UTF-8?q?chore(models):=20=E4=BC=98=E5=8C=96MAA=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/MAA.py | 23 ++++------------------- app/services/system.py | 11 +++++++++++ resources/version.json | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/models/MAA.py b/app/models/MAA.py index cb23665..c6fef53 100644 --- a/app/models/MAA.py +++ b/app/models/MAA.py @@ -37,7 +37,7 @@ from pathlib import Path from typing import List from app.core import Config -from app.services import Notify +from app.services import Notify, System class MaaManager(QObject): @@ -265,12 +265,7 @@ class MaaManager(QObject): # 此时,log变量内存储的就是出现异常的日志信息,可以保存或发送用于问题排查 self.update_log_text.emit(result) # 无命令行中止MAA与其子程序 - killprocess = subprocess.Popen( - f"taskkill /F /T /PID {maa.pid}", - shell=True, - creationflags=subprocess.CREATE_NO_WINDOW, - ) - killprocess.wait() + System.kill_process(self.maa_exe_path) self.if_open_emulator = True # 推送异常通知 Notify.push_notification( @@ -372,12 +367,7 @@ class MaaManager(QObject): else: self.update_log_text.emit(result) # 无命令行中止MAA与其子程序 - killprocess = subprocess.Popen( - f"taskkill /F /T /PID {maa.pid}", - shell=True, - creationflags=subprocess.CREATE_NO_WINDOW, - ) - killprocess.wait() + System.kill_process(self.maa_exe_path) self.if_open_emulator = True for _ in range(10): if self.isInterruptionRequested: @@ -465,12 +455,7 @@ class MaaManager(QObject): # 关闭可能未正常退出的MAA进程 if self.isInterruptionRequested: - killprocess = subprocess.Popen( - f"taskkill /F /T /PID {maa.pid}", - shell=True, - creationflags=subprocess.CREATE_NO_WINDOW, - ) - killprocess.wait() + System.kill_process(self.maa_exe_path) # 更新用户数据 modes = [self.data[_[2]][15] for _ in self.user_list] diff --git a/app/services/system.py b/app/services/system.py index 5ff3e6d..383a965 100644 --- a/app/services/system.py +++ b/app/services/system.py @@ -177,6 +177,17 @@ class _SystemHandler: win32gui.EnumWindows(callback, window_info) return window_info + def kill_process(self, path: Path) -> None: + """根据路径中止进程""" + + for pid in self.search_pids(path): + killprocess = subprocess.Popen( + f"taskkill /F /T /PID {pid}", + shell=True, + creationflags=subprocess.CREATE_NO_WINDOW, + ) + killprocess.wait() + def search_pids(path: Path) -> list: """根据路径查找进程PID""" diff --git a/resources/version.json b/resources/version.json index 51af90d..f8f2340 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,7 +1,7 @@ { "main_version": "4.2.3.1", "updater_version": "1.1.1.3", - "announcement": "\n## 新增功能\n- 添加`简洁用户列表下相邻两个任务间的切换方式`可选项\n## 修复BUG\n- 修复静默代理标记移除异常情况\n## 程序优化\n- 暂无", + "announcement": "\n## 新增功能\n- 添加`简洁用户列表下相邻两个任务间的切换方式`可选项\n## 修复BUG\n- 修复静默代理标记移除异常情况\n## 程序优化\n- 优化MAA关闭方法", "proxy_list": [ "", "https://gitproxy.click/",