From ec24e776e7c02d9d56f0dd8f4c2cc5e5ae79ed45 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Sat, 9 Nov 2024 16:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D#9=E4=B8=8E=E4=BA=BA=E5=B7=A5?= =?UTF-8?q?=E6=8E=92=E6=9F=A5=E6=A8=A1=E5=BC=8F=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AUTO_MAA.py | 101 +++++++++++++++++++++++------------------------ gui/ui/main.ui | 2 +- res/version.json | 8 ++-- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/AUTO_MAA.py b/AUTO_MAA.py index 3e5765a..0811c99 100644 --- a/AUTO_MAA.py +++ b/AUTO_MAA.py @@ -27,6 +27,7 @@ v4.1 from PySide6.QtWidgets import ( QWidget, + QMainWindow, QApplication, QInputDialog, QFileDialog, @@ -83,7 +84,6 @@ class MaaRunner(QtCore.QThread): app_path = os.path.dirname(os.path.realpath(sys.argv[0])).replace( "\\", "/" ) # 获取软件自身的路径 - if_run = False def __init__( self, set_path, log_path, maa_path, routine, annihilation, num, data, mode @@ -102,7 +102,6 @@ class MaaRunner(QtCore.QThread): def run(self): """主进程,运行MAA代理进程""" - self.if_run = True curdate = server_date() begin_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") self.data = sorted(self.data, key=lambda x: (-len(x[15]), x[16])) @@ -124,18 +123,18 @@ class MaaRunner(QtCore.QThread): self.data[_][0] += "_第" + str(self.data[_][14] + 1) + "次代理" # 开始代理 for index in all_index: - if not self.if_run: + if self.isInterruptionRequested(): break # 初始化代理情况记录和模式替换记录 run_book = [False for _ in range(2)] mode_book = ["日常代理_剿灭", "日常代理_日常"] # 尝试次数循环 for i in range(self.num): - if not self.if_run: + if self.isInterruptionRequested(): break # 剿灭-日常模式循环 for j in range(2): - if not self.if_run: + if self.isInterruptionRequested(): break if j == 0 and self.data[index][10] == "n": run_book[0] = True @@ -157,7 +156,7 @@ class MaaRunner(QtCore.QThread): if (not _ in over_index + error_index + [index]) ] # 监测MAA运行状态 - while self.if_run: + while not self.isInterruptionRequested(): # 获取MAA日志 logs = self.get_maa_log(start_time) # 判断是否超时 @@ -262,7 +261,7 @@ class MaaRunner(QtCore.QThread): + "出现异常", 1, ) - if self.if_run: + if not self.isInterruptionRequested(): time.sleep(10) break if run_book[0] and run_book[1]: @@ -290,13 +289,13 @@ class MaaRunner(QtCore.QThread): self.data[_][0] += "_排查模式" # 开始排查 for index in all_index: - if not self.if_run: + if self.isInterruptionRequested(): break if self.data[index][15] == "beta": if_strat_app = True run_book = [False for _ in range(2)] # 启动重试循环 - while self.if_run: + while not self.isInterruptionRequested(): # 配置MAA if if_strat_app: self.set_maa("人工排查_启动模拟器", index) @@ -314,7 +313,7 @@ class MaaRunner(QtCore.QThread): if (not _ in over_index + error_index + [index]) ] # 监测MAA运行状态 - while self.if_run: + while not self.isInterruptionRequested(): # 获取MAA日志 logs = self.get_maa_log(start_time) # 合并日志 @@ -322,11 +321,7 @@ class MaaRunner(QtCore.QThread): # 更新MAA日志 if len(logs) > 100: self.update_gui.emit( - self.data[index][0] - + "_第" - + str(i + 1) - + "次_" - + mode_book[j][5:7], + self.data[index][0], "\n".join([self.data[_][0] for _ in wait_index]), "\n".join([self.data[_][0] for _ in over_index]), "\n".join([self.data[_][0] for _ in error_index]), @@ -334,11 +329,7 @@ class MaaRunner(QtCore.QThread): ) else: self.update_gui.emit( - self.data[index][0] - + "_第" - + str(i + 1) - + "次_" - + mode_book[j][5:7], + self.data[index][0], "\n".join([self.data[_][0] for _ in wait_index]), "\n".join([self.data[_][0] for _ in over_index]), "\n".join([self.data[_][0] for _ in error_index]), @@ -374,12 +365,12 @@ class MaaRunner(QtCore.QThread): ) killprocess.wait() if_strat_app = True - if self.if_run: + if not self.isInterruptionRequested(): time.sleep(10) break if run_book[0]: break - elif self.if_run: + elif not self.isInterruptionRequested(): self.question_title = "操作提示" self.question_info = "MAA未能正确登录到PRTS,是否重试?" self.question_choice = "wait" @@ -388,7 +379,7 @@ class MaaRunner(QtCore.QThread): time.sleep(1) if self.question_choice == "No": break - if run_book[0] and self.if_run: + if run_book[0] and not self.isInterruptionRequested(): self.question_title = "操作提示" self.question_info = "请检查用户代理情况,如无异常请按下确认键。" self.question_choice = "wait" @@ -416,7 +407,7 @@ class MaaRunner(QtCore.QThread): # 记录当前时间 start_time = datetime.datetime.now() # 监测MAA运行状态 - while self.if_run: + while not self.isInterruptionRequested(): # 获取MAA日志 logs = self.get_maa_log(start_time) # 合并日志 @@ -433,10 +424,9 @@ class MaaRunner(QtCore.QThread): elif "用户" in self.mode: self.get_json.emit(self.get_json_path) self.accomplish.emit() - self.if_run = False if self.mode in ["日常代理", "人工排查"]: # 关闭可能未正常退出的MAA进程 - if not self.if_run: + if self.isInterruptionRequested(): killprocess = subprocess.Popen( "taskkill /F /T /PID " + str(maa.pid), shell=True, @@ -490,7 +480,6 @@ class MaaRunner(QtCore.QThread): 10, ) self.accomplish.emit() - self.if_run = False def get_maa_log(self, start_time): """获取MAA日志""" @@ -529,7 +518,7 @@ class MaaRunner(QtCore.QThread): return "检测到MAA进程异常\n正在中止相关程序\n请等待10s" elif self.if_time_out: return "检测到MAA进程超时\n正在中止相关程序\n请等待10s" - elif not self.if_run: + elif self.isInterruptionRequested(): return "您中止了本次任务\n正在中止相关程序\n请等待" else: return "Wait" @@ -542,7 +531,7 @@ class MaaRunner(QtCore.QThread): or ("MaaAssistantArknights GUI exited" in log) ): return "检测到MAA进程异常\n正在中止相关程序\n请等待10s" - elif not self.if_run: + elif self.isInterruptionRequested(): return "您中止了本次任务\n正在中止相关程序\n请等待" else: return "Wait" @@ -968,7 +957,7 @@ class MainTimer(QtCore.QThread): def run(self): """主功能代码,实现定时执行以及相关配置信息的实时同步""" - while True: + while not self.isInterruptionRequested(): self.get_config.emit() self.set_system() time_set = [ @@ -1114,7 +1103,6 @@ class Main(QWidget): ] self.ui = uiLoader.load(self.app_path + "/gui/ui/main.ui") - self.ui.setWindowIcon(QIcon(self.app_path + "/gui/ico/AUTO_MAA.ico")) # 检查文件完整性 self.initialize() self.check_config() @@ -1199,6 +1187,9 @@ class Main(QWidget): self.check_update = self.ui.findChild(QPushButton, "pushButton_check_update") self.check_update.clicked.connect(self.check_version) + self.tips = self.ui.findChild(QTextBrowser, "textBrowser_tips") + self.tips.setOpenExternalLinks(True) + self.run_text = self.ui.findChild(QTextBrowser, "textBrowser_run") self.wait_text = self.ui.findChild(QTextBrowser, "textBrowser_wait") self.over_text = self.ui.findChild(QTextBrowser, "textBrowser_over") @@ -2321,13 +2312,6 @@ class Main(QWidget): self.MainTimer.is_maa_run = True self.MaaRunner.start() - def maa_ender(self, mode): - """中止MAA线程""" - self.MaaRunner.if_run = False - self.MaaRunner.wait() - self.MainTimer.is_maa_run = False - self.maa_running_set(mode) - def maa_running_set(self, mode): """处理MAA运行过程中的GUI组件变化""" if "开始" in mode: @@ -2397,6 +2381,14 @@ class Main(QWidget): self.run_now.setText("立即执行") self.run_now.clicked.connect(self.routine_starter) + def maa_ender(self, mode): + """中止MAA线程""" + self.MainTimer.quit() + self.MaaRunner.requestInterruption() + self.MaaRunner.wait() + self.MainTimer.is_maa_run = False + self.maa_running_set(mode) + def check_version(self): """检查版本更新,调起文件下载进程""" # 从本地版本信息文件获取当前版本信息 @@ -2486,22 +2478,27 @@ class Main(QWidget): """同步配置文件到子线程""" self.MainTimer.config = self.config - def closeEvent(self, event): - """清理残余进程""" - self.MainTimer.quit() - self.MaaRunner.if_run = False - self.MaaRunner.wait() - self.cur.close() - self.db.close() - super().closeEvent(event) - -class AUTO_MAA(QApplication): +class AUTO_MAA(QMainWindow): def __init__(self): super().__init__() self.main = Main() - self.main.ui.show() + self.setCentralWidget(self.main.ui) + self.setWindowIcon(QIcon(self.main.app_path + "/gui/ico/AUTO_MAA.ico")) + self.setWindowTitle("AUTO_MAA") + + def closeEvent(self, event): + """清理残余进程""" + self.main.MainTimer.requestInterruption() + self.main.MainTimer.quit() + self.main.MainTimer.wait() + self.main.MaaRunner.requestInterruption() + self.main.MaaRunner.quit() + self.main.MaaRunner.wait() + self.main.cur.close() + self.main.db.close() + event.accept() def server_date(): @@ -2513,5 +2510,7 @@ def server_date(): if __name__ == "__main__": - app = AUTO_MAA() - app.exec() + app = QApplication(sys.argv) + window = AUTO_MAA() + window.show() + sys.exit(app.exec()) diff --git a/gui/ui/main.ui b/gui/ui/main.ui index 3b519b4..ab3e504 100644 --- a/gui/ui/main.ui +++ b/gui/ui/main.ui @@ -1257,7 +1257,7 @@ - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css"> diff --git a/res/version.json b/res/version.json index 2e8a116..09f659d 100644 --- a/res/version.json +++ b/res/version.json @@ -1,7 +1,7 @@ { - "main_version": "4.1.2.0", - "main_download_url": "https://ghp.ci/https://github.com/DLmaster361/AUTO_MAA/releases/download/v4.1.2/AUTO_MAA_v4.1.2.zip", + "main_version": "4.1.2.1", + "main_download_url": "https://ghp.ci/https://github.com/DLmaster361/AUTO_MAA/releases/download/v4.1.2_beta/AUTO_MAA_v4.1.2.zip", "updater_version": "1.0.2.0", - "updater_download_url": "https://ghp.ci/https://github.com/DLmaster361/AUTO_MAA/releases/download/v4.1.2/Updater_v1.0.2.zip", - "announcement": "\n# 公测版,若出现问题请及时反馈给项目组!\n## 新增功能\n- 添加`启动AUTO_MAA后直接代理`功能\n- 添加无限代理天数模式\n## 修复BUG\n- 尝试解决卡日志情况\n## 程序优化\n- Updater.exe图标更换\n- 更新逻辑优化" + "updater_download_url": "https://ghp.ci/https://github.com/DLmaster361/AUTO_MAA/releases/download/v4.1.2_beta/Updater_v1.0.2.zip", + "announcement": "\n# 公测版,若出现问题请及时反馈给项目组!\n## 新增功能\n- 添加`启动AUTO_MAA后直接代理`功能\n- 添加无限代理天数模式\n## 修复BUG\n- 通过限制日志长度解决卡日志情况\n- 修复tips链接无法打开问题 #9\n- 修复正常退出窗口显示停止工作问题 #9\n## 程序优化\n- Updater.exe图标更换\n- 更新逻辑优化\n- GUI窗口逻辑优化" } \ No newline at end of file