diff --git a/app/ui/main_window.py b/app/ui/main_window.py index ee6e82d..227db62 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -45,6 +45,7 @@ from qfluentwidgets import ( ) from PySide6.QtGui import QIcon, QCloseEvent from PySide6.QtCore import Qt, QTimer +import json from app.core import Config, TaskManager, MainTimer, MainInfoBar from app.services import Notify, Crypto, System @@ -142,22 +143,17 @@ class AUTO_MAA(MSFluentWindow): self.tray_menu.addSeparator() # 开始任务菜单项 - # self.tray_menu.addActions( - # [ - # Action( - # FluentIcon.PLAY, - # "运行自动代理", - # triggered=lambda: self.start_task("自动代理"), - # ), - # Action( - # FluentIcon.PLAY, - # "运行人工排查", - # triggered=lambda: self.start_task("人工排查"), - # ), - # Action(FluentIcon.PAUSE, "中止当前任务", triggered=self.stop_task), - # ] - # ) - # self.tray_menu.addSeparator() + self.tray_menu.addActions( + [ + Action(FluentIcon.PLAY, "运行自动代理", triggered=self.start_main_task), + Action( + FluentIcon.PAUSE, + "中止所有任务", + triggered=lambda: TaskManager.stop_task("ALL"), + ), + ] + ) + self.tray_menu.addSeparator() # 退出主程序菜单项 self.tray_menu.addAction( @@ -228,6 +224,11 @@ class AUTO_MAA(MSFluentWindow): info.addWidget(Up) info.show() + # 直接运行主任务 + if Config.global_config.get(Config.global_config.start_IfRunDirectly): + + self.start_main_task() + def set_min_method(self) -> None: """设置最小化方法""" @@ -246,40 +247,32 @@ class AUTO_MAA(MSFluentWindow): if reason == QSystemTrayIcon.DoubleClick: self.show_ui("显示主窗口") - # def start_task(self, mode): - # """调起对应任务""" - # if self.main.MaaManager.isRunning(): - # Notify.push_notification( - # f"无法运行{mode}!", - # "当前已有任务正在运行,请在该任务结束后重试", - # "当前已有任务正在运行,请在该任务结束后重试", - # 3, - # ) - # else: - # self.main.maa_starter(mode) + def start_main_task(self) -> None: + """启动主任务""" - # def stop_task(self): - # """中止当前任务""" - # if self.main.MaaManager.isRunning(): - # if ( - # self.main.MaaManager.mode == "自动代理" - # or self.main.MaaManager.mode == "人工排查" - # ): - # self.main.maa_ender(f"{self.main.MaaManager.mode}_结束") - # elif "设置MAA" in self.main.MaaManager.mode: - # Notify.push_notification( - # "正在设置MAA!", - # "正在运行设置MAA任务,无法中止", - # "正在运行设置MAA任务,无法中止", - # 3, - # ) - # else: - # Notify.push_notification( - # "无任务运行!", - # "当前无任务正在运行,无需中止", - # "当前无任务正在运行,无需中止", - # 3, - # ) + if (Config.app_path / "config/QueueConfig/调度队列_1.json").exists(): + + with (Config.app_path / "config/QueueConfig/调度队列_1.json").open( + mode="r", encoding="utf-8" + ) as f: + info = json.load(f) + + logger.info("自动添加任务:调度队列_1") + TaskManager.add_task("自动代理_主调度台", "主任务队列", info) + + elif (Config.app_path / "config/MaaConfig/脚本_1").exists(): + + info = {"Queue": {"Member_1": "脚本_1"}} + + logger.info("自动添加任务:脚本_1") + TaskManager.add_task("自动代理_主调度台", "主任务队列", info) + + else: + + logger.worning("启动主任务失败:未找到有效的主任务配置文件") + MainInfoBar.push_info_bar( + "warning", "启动主任务失败", "“调度队列_1”与“脚本_1”均不存在", -1 + ) def show_ui(self, mode: str, if_quick: bool = False) -> None: """配置窗口状态""" diff --git a/app/ui/setting.py b/app/ui/setting.py index 66d4f9d..e080f7b 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -484,8 +484,8 @@ class StartSettingCard(HeaderCardWidget): ) self.card_IfRunDirectly = SwitchSettingCard( icon=FluentIcon.PAGE_RIGHT, - title="启动后直接运行", - content="启动AUTO_MAA后自动运行任务(暂不可用)", + title="启动后直接运行主任务", + content="启动AUTO_MAA后自动运行自动代理任务,优先级:调度队列 1 > 脚本 1", configItem=Config.global_config.start_IfRunDirectly, ) diff --git a/resources/version.json b/resources/version.json index 7d513a3..e7896a0 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,7 +1,7 @@ { - "main_version": "4.2.3.2", + "main_version": "4.2.3.3", "updater_version": "1.1.1.3", - "announcement": "\n## 新增功能\n- 添加`简洁用户列表下相邻两个任务间的切换方式`可选项\n## 修复BUG\n- 修复静默代理标记移除异常情况\n- 适配深色模式 #18\n## 程序优化\n- 优化MAA关闭方法\n- 添加高级代理文件校验过程\n- 升级日志监看方法\n- 优化主调度台默认选项", + "announcement": "\n## 新增功能\n- 添加`简洁用户列表下相邻两个任务间的切换方式`可选项\n- 恢复启动后直接运行主任务功能以及相关托盘菜单\n## 修复BUG\n- 修复静默代理标记移除异常情况\n- 适配深色模式 #18\n## 程序优化\n- 优化MAA关闭方法\n- 添加高级代理文件校验过程\n- 升级日志监看方法\n- 优化主调度台默认选项", "proxy_list": [ "", "https://gitproxy.click/",