chore(models): 优化MAA关闭方法

This commit is contained in:
DLmaster
2025-02-12 22:15:17 +08:00
parent 7dc057e30f
commit d45da439bd
3 changed files with 16 additions and 20 deletions

View File

@@ -37,7 +37,7 @@ from pathlib import Path
from typing import List from typing import List
from app.core import Config from app.core import Config
from app.services import Notify from app.services import Notify, System
class MaaManager(QObject): class MaaManager(QObject):
@@ -265,12 +265,7 @@ class MaaManager(QObject):
# 此时log变量内存储的就是出现异常的日志信息可以保存或发送用于问题排查 # 此时log变量内存储的就是出现异常的日志信息可以保存或发送用于问题排查
self.update_log_text.emit(result) self.update_log_text.emit(result)
# 无命令行中止MAA与其子程序 # 无命令行中止MAA与其子程序
killprocess = subprocess.Popen( System.kill_process(self.maa_exe_path)
f"taskkill /F /T /PID {maa.pid}",
shell=True,
creationflags=subprocess.CREATE_NO_WINDOW,
)
killprocess.wait()
self.if_open_emulator = True self.if_open_emulator = True
# 推送异常通知 # 推送异常通知
Notify.push_notification( Notify.push_notification(
@@ -372,12 +367,7 @@ class MaaManager(QObject):
else: else:
self.update_log_text.emit(result) self.update_log_text.emit(result)
# 无命令行中止MAA与其子程序 # 无命令行中止MAA与其子程序
killprocess = subprocess.Popen( System.kill_process(self.maa_exe_path)
f"taskkill /F /T /PID {maa.pid}",
shell=True,
creationflags=subprocess.CREATE_NO_WINDOW,
)
killprocess.wait()
self.if_open_emulator = True self.if_open_emulator = True
for _ in range(10): for _ in range(10):
if self.isInterruptionRequested: if self.isInterruptionRequested:
@@ -465,12 +455,7 @@ class MaaManager(QObject):
# 关闭可能未正常退出的MAA进程 # 关闭可能未正常退出的MAA进程
if self.isInterruptionRequested: if self.isInterruptionRequested:
killprocess = subprocess.Popen( System.kill_process(self.maa_exe_path)
f"taskkill /F /T /PID {maa.pid}",
shell=True,
creationflags=subprocess.CREATE_NO_WINDOW,
)
killprocess.wait()
# 更新用户数据 # 更新用户数据
modes = [self.data[_[2]][15] for _ in self.user_list] modes = [self.data[_[2]][15] for _ in self.user_list]

View File

@@ -177,6 +177,17 @@ class _SystemHandler:
win32gui.EnumWindows(callback, window_info) win32gui.EnumWindows(callback, window_info)
return 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: def search_pids(path: Path) -> list:
"""根据路径查找进程PID""" """根据路径查找进程PID"""

View File

@@ -1,7 +1,7 @@
{ {
"main_version": "4.2.3.1", "main_version": "4.2.3.1",
"updater_version": "1.1.1.3", "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": [ "proxy_list": [
"", "",
"https://gitproxy.click/", "https://gitproxy.click/",