feat(core):初步完成定时执行功能开发

This commit is contained in:
DLmaster
2025-01-25 18:00:56 +08:00
parent ff7e433634
commit 7e08c88a3e
64 changed files with 5858 additions and 508 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

359
app/ui/dispatch_center.py Normal file
View File

@@ -0,0 +1,359 @@
# <AUTO_MAA:A MAA Multi Account Management and Automation Tool>
# Copyright © <2024> <DLmaster361>
# This file is part of AUTO_MAA.
# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.
# DLmaster_361@163.com
"""
AUTO_MAA
AUTO_MAA调度中枢界面
v4.2
作者DLmaster_361
"""
from loguru import logger
from PySide6.QtWidgets import (
QWidget,
QVBoxLayout,
QStackedWidget,
QHBoxLayout,
)
from qfluentwidgets import (
CardWidget,
IconWidget,
BodyLabel,
qconfig,
Pivot,
ScrollArea,
FluentIcon,
MessageBox,
HeaderCardWidget,
CommandBar,
FluentIcon,
TextBrowser,
ComboBox,
setTheme,
Theme,
SubtitleLabel,
PushButton,
ElevatedCardWidget,
)
from PySide6.QtUiTools import QUiLoader
from PySide6 import QtCore
from typing import List, Dict
import json
import shutil
uiLoader = QUiLoader()
from app.core import AppConfig, TaskManager, Task, MainInfoBar
from app.services import Notification
class DispatchCenter(QWidget):
def __init__(self, config: AppConfig, task_manager: TaskManager, parent=None):
super().__init__(parent)
self.setObjectName("调度中枢")
self.config = config
self.task_manager = task_manager
self.pivot = Pivot(self)
self.stackedWidget = QStackedWidget(self)
self.Layout = QVBoxLayout(self)
self.script_list: Dict[str, DispatchBox] = {}
dispatch_box = DispatchBox(self.config, "主调度台", self)
self.script_list["主调度台"] = dispatch_box
self.stackedWidget.addWidget(self.script_list["主调度台"])
self.pivot.addItem(
routeKey="主调度台",
text="主调度台",
onClick=self.update_top_bar,
icon=FluentIcon.CAFE,
)
self.update_top_bar()
self.Layout.addWidget(self.pivot, 0, QtCore.Qt.AlignHCenter)
self.Layout.addWidget(self.stackedWidget)
self.Layout.setContentsMargins(0, 0, 0, 0)
self.pivot.currentItemChanged.connect(
lambda index: self.stackedWidget.setCurrentWidget(self.script_list[index])
)
def add_board(self, task: Task) -> None:
"""添加一个调度台界面"""
dispatch_box = DispatchBox(self.config, task.name, self)
dispatch_box.top_bar.button.clicked.connect(
lambda: self.task_manager.stop_task(task.name)
)
task.create_task_list.connect(dispatch_box.info.task.create_task)
task.create_user_list.connect(dispatch_box.info.user.create_user)
task.update_task_list.connect(dispatch_box.info.task.update_task)
task.update_user_list.connect(dispatch_box.info.user.update_user)
task.update_log_text.connect(dispatch_box.info.log_text.text.setText)
task.accomplish.connect(lambda: self.del_board(f"调度台_{task.name}"))
self.script_list[f"调度台_{task.name}"] = dispatch_box
self.stackedWidget.addWidget(self.script_list[f"调度台_{task.name}"])
self.pivot.addItem(routeKey=f"调度台_{task.name}", text=f"调度台 {task.name}")
def del_board(self, name: str) -> None:
"""删除指定子界面"""
self.pivot.setCurrentItem("主调度台")
self.stackedWidget.removeWidget(self.script_list[name])
self.script_list[name].deleteLater()
self.pivot.removeWidget(name)
def update_top_bar(self):
"""更新顶栏"""
list = []
if (self.config.app_path / "config/QueueConfig").exists():
for json_file in (self.config.app_path / "config/QueueConfig").glob(
"*.json"
):
list.append(f"队列 - {json_file.stem}")
if (self.config.app_path / "config/MaaConfig").exists():
for subdir in (self.config.app_path / "config/MaaConfig").iterdir():
if subdir.is_dir():
list.append(f"实例 - Maa - {subdir.name}")
self.script_list["主调度台"].top_bar.object.clear()
self.script_list["主调度台"].top_bar.object.addItems(list)
class DispatchBox(QWidget):
def __init__(self, config: AppConfig, name: str, parent=None):
super().__init__(parent)
self.setObjectName(name)
self.config = config
layout = QVBoxLayout()
scrollArea = ScrollArea()
scrollArea.setWidgetResizable(True)
content_widget = QWidget()
content_layout = QVBoxLayout(content_widget)
self.top_bar = self.DispatchTopBar(self, name)
self.info = self.DispatchInfoCard(self)
content_layout.addWidget(self.top_bar)
content_layout.addWidget(self.info)
scrollArea.setWidget(content_widget)
layout.addWidget(scrollArea)
self.setLayout(layout)
class DispatchTopBar(CardWidget):
def __init__(self, parent=None, name: str = None):
super().__init__(parent)
Layout = QHBoxLayout(self)
if name == "主调度台":
self.object = ComboBox()
self.object.setCurrentIndex(-1)
self.object.setPlaceholderText("请选择调度对象")
self.mode = ComboBox()
self.mode.addItems(["自动代理", "人工排查"])
self.mode.setCurrentIndex(-1)
self.mode.setPlaceholderText("请选择调度模式")
self.button = PushButton("开始任务")
Layout.addWidget(self.object)
Layout.addWidget(self.mode)
Layout.addStretch(1)
Layout.addWidget(self.button)
else:
self.Lable = SubtitleLabel(name, self)
self.button = PushButton("中止任务")
Layout.addWidget(self.Lable)
Layout.addStretch(1)
Layout.addWidget(self.button)
class DispatchInfoCard(HeaderCardWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("调度信息")
self.task = self.TaskInfoCard(self)
self.user = self.UserInfoCard(self)
self.log_text = self.LogCard(self)
self.viewLayout.addWidget(self.task)
self.viewLayout.addWidget(self.user)
self.viewLayout.addWidget(self.log_text)
self.viewLayout.setStretch(0, 1)
self.viewLayout.setStretch(1, 1)
self.viewLayout.setStretch(2, 5)
def update_board(self, task_list: list, user_list: list, log: str):
"""更新调度信息"""
self.task.update_task(task_list)
self.user.update_user(user_list)
self.log_text.text.setText(log)
class TaskInfoCard(HeaderCardWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("任务队列")
self.Layout = QVBoxLayout()
self.viewLayout.addLayout(self.Layout)
self.viewLayout.setContentsMargins(3, 0, 3, 3)
self.task_cards: List[ItemCard] = []
def create_task(self, task_list: list):
"""创建任务队列"""
while self.Layout.count() > 0:
item = self.Layout.takeAt(0)
if item.spacerItem():
self.Layout.removeItem(item.spacerItem())
elif item.widget():
item.widget().deleteLater()
self.task_cards = []
for task in task_list:
self.task_cards.append(ItemCard(task))
self.Layout.addWidget(self.task_cards[-1])
self.Layout.addStretch(1)
def update_task(self, task_list: list):
"""更新任务队列"""
for i in range(len(task_list)):
self.task_cards[i].update_status(task_list[i][1])
class UserInfoCard(HeaderCardWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("用户队列")
self.Layout = QVBoxLayout()
self.viewLayout.addLayout(self.Layout)
self.viewLayout.setContentsMargins(3, 0, 3, 3)
self.user_cards: List[ItemCard] = []
def create_user(self, user_list: list):
"""创建用户队列"""
while self.Layout.count() > 0:
item = self.Layout.takeAt(0)
if item.spacerItem():
self.Layout.removeItem(item.spacerItem())
elif item.widget():
item.widget().deleteLater()
self.user_cards = []
for user in user_list:
self.user_cards.append(ItemCard(user))
self.Layout.addWidget(self.user_cards[-1])
self.Layout.addStretch(1)
def update_user(self, user_list: list):
"""更新用户队列"""
for i in range(len(user_list)):
self.user_cards[i].Label.setText(user_list[i][0])
self.user_cards[i].update_status(user_list[i][1])
class LogCard(HeaderCardWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("日志")
self.text = TextBrowser()
self.viewLayout.setContentsMargins(3, 0, 3, 3)
self.viewLayout.addWidget(self.text)
class ItemCard(CardWidget):
def __init__(self, task_item: list, parent=None):
super().__init__(parent)
self.Layout = QHBoxLayout(self)
self.Label = BodyLabel(task_item[0], self)
self.icon = IconWidget(FluentIcon.MORE, self)
self.icon.setFixedSize(16, 16)
self.update_status(task_item[1])
self.Layout.addWidget(self.icon)
self.Layout.addWidget(self.Label)
self.Layout.addStretch(1)
def update_status(self, status: str):
if status == "完成":
self.icon.setIcon(FluentIcon.ACCEPT)
self.Label.setTextColor("#0eb840", "#0eb840")
elif status == "等待":
self.icon.setIcon(FluentIcon.MORE)
self.Label.setTextColor("#7397ab", "#7397ab")
elif status == "运行":
self.icon.setIcon(FluentIcon.PLAY)
self.Label.setTextColor("#2e4e7e", "#2e4e7e")
elif status == "跳过":
self.icon.setIcon(FluentIcon.REMOVE)
self.Label.setTextColor("#606060", "#d2d2d2")
elif status == "异常":
self.icon.setIcon(FluentIcon.CLOSE)
self.Label.setTextColor("#ff2121", "#ff2121")

View File

@@ -75,7 +75,7 @@ class Main(QWidget):
# self.run_now: PushButton = self.ui.findChild(PushButton, "pushButton_runnow")
# self.run_now.setIcon(FluentIcon.PLAY)
# self.run_now.clicked.connect(lambda: self.maa_starter("日常代理"))
# self.run_now.clicked.connect(lambda: self.maa_starter("自动代理"))
# self.check_start: PushButton = self.ui.findChild(
# PushButton, "pushButton_checkstart"
@@ -182,7 +182,7 @@ class Main(QWidget):
self.MaaManager.update_user_info.connect(self.change_user_info)
self.MaaManager.push_notification.connect(self.notify.push_notification)
self.MaaManager.send_mail.connect(self.notify.send_mail)
self.MaaManager.accomplish.connect(lambda: self.maa_ender("日常代理_结束"))
self.MaaManager.accomplish.connect(lambda: self.maa_ender("自动代理_结束"))
self.MaaManager.get_json.connect(self.get_maa_config)
self.MaaManager.set_silence.connect(self.switch_silence)
@@ -199,7 +199,7 @@ class Main(QWidget):
# 启动后直接开始代理
if self.config.content["Default"]["SelfSet.IfProxyDirectly"] == "True":
self.maa_starter("日常代理")
self.maa_starter("自动代理")
@@ -275,39 +275,7 @@ class Main(QWidget):
# self.start_time[i][1].setTime(time)
# self.if_update_config = True
def update_board(self, run_text, wait_text, over_text, error_text, log_text):
"""写入数据至GUI执行界面的调度台面板"""
self.run_text.setPlainText(run_text)
self.wait_text.setPlainText(wait_text)
self.over_text.setPlainText(over_text)
self.error_text.setPlainText(error_text)
self.log_text.setPlainText(log_text)
self.log_text.verticalScrollBar().setValue(
self.log_text.verticalScrollBar().maximum()
)
def change_user_info(self, modes, uids, days, lasts, notes, numbs):
"""将代理完成后发生改动的用户信息同步至本地数据库"""
for index in range(len(uids)):
self.config.cur.execute(
"UPDATE adminx SET day = ? WHERE mode = ? AND uid = ?",
(days[index], modes[index], uids[index]),
)
self.config.cur.execute(
"UPDATE adminx SET last = ? WHERE mode = ? AND uid = ?",
(lasts[index], modes[index], uids[index]),
)
self.config.cur.execute(
"UPDATE adminx SET notes = ? WHERE mode = ? AND uid = ?",
(notes[index], modes[index], uids[index]),
)
self.config.cur.execute(
"UPDATE adminx SET numb = ? WHERE mode = ? AND uid = ?",
(numbs[index], modes[index], uids[index]),
)
self.config.db.commit()
# 同步用户信息更改至GUI
self.update_user_info("normal")
@@ -431,115 +399,7 @@ class Main(QWidget):
self.user_list_simple.setStyleSheet("QTableWidget::item {}")
self.user_list_beta.setStyleSheet("QTableWidget::item {}")
def read(self, operation):
"""弹出对话框组件进行读入"""
class InputMessageBox(MessageBoxBase):
"""输入对话框"""
def __init__(self, parent, title: str, content: str, mode: str):
super().__init__(parent)
self.title = SubtitleLabel(title)
if mode == "明文":
self.input = LineEdit()
elif mode == "密码":
self.input = PasswordLineEdit()
self.input.setPlaceholderText(content)
self.input.setClearButtonEnabled(True)
# 将组件添加到布局中
self.viewLayout.addWidget(self.title)
self.viewLayout.addWidget(self.input)
# 读入PASSWORD
if operation == "key":
choice = InputMessageBox(self.ui, "请输入管理密钥", "管理密钥", "密码")
if choice.exec() and choice.input.text() != "":
self.PASSWORD = choice.input.text()
self.update_user_info("normal")
elif operation == "oldkey":
choice = InputMessageBox(
self.ui, "请输入旧的管理密钥", "旧管理密钥", "密码"
)
if choice.exec() and choice.input.text() != "":
self.PASSWORD = choice.input.text()
return True
else:
return False
elif operation == "newkey":
choice = InputMessageBox(
self.ui, "请输入新的管理密钥", "新管理密钥", "密码"
)
if choice.exec() and choice.input.text() != "":
return choice.input.text()
else:
return None
elif operation == "setkey":
choice = InputMessageBox(
self.ui,
"未检测到管理密钥,请设置您的管理密钥",
"管理密钥",
"密码",
)
if choice.exec() and choice.input.text() != "":
self.PASSWORD = choice.input.text()
return True
else:
return False
# 读入选择
elif operation == "question_runner":
choice = MessageBox(
self.MaaManager.question_title,
self.MaaManager.question_info,
None,
)
if choice.exec():
self.MaaManager.question_choice = "Yes"
else:
self.MaaManager.question_choice = "No"
# 读入MAA文件目录
elif operation == "file_path_maa":
file_path = QFileDialog.getExistingDirectory(self.ui, "选择MAA文件夹")
if file_path:
self.maa_path.setText(file_path)
# 读入自定义基建文件目录
elif operation == "file_path_infrastructure":
file_path, _ = QFileDialog.getOpenFileName(
self.ui, "选择自定义基建文件", "", "JSON 文件 (*.json)"
)
return file_path
def timed_start(self):
"""定时启动代理任务"""
# 获取定时列表
time_set = [
self.config.content["Default"][f"TimeSet.run{_ + 1}"]
for _ in range(10)
if self.config.content["Default"][f"TimeSet.set{_ + 1}"] == "True"
]
# 按时间调起代理任务
curtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
if (
curtime[11:16] in time_set
and curtime != self.last_time
and not self.MaaManager.isRunning()
):
self.last_time = curtime
self.maa_starter("日常代理")
def switch_silence(self, mode, emulator_path, boss_key):
"""切换静默模式"""
@@ -557,16 +417,7 @@ class Main(QWidget):
self.Timer.timeout.connect(self.set_system)
self.Timer.timeout.connect(self.timed_start)
def set_silence(self, emulator_path, boss_key):
"""设置静默模式"""
windows = self.get_window_info()
if any(emulator_path in _ for _ in windows):
try:
pyautogui.hotkey(*boss_key)
except pyautogui.FailSafeException as e:
# 执行日志记录,暂时缺省
pass
def maa_starter(self, mode):
"""启动MaaManager线程运行任务"""
@@ -620,14 +471,14 @@ class Main(QWidget):
self.update_user_info("read_only")
if mode == "日常代理_开始":
if mode == "自动代理_开始":
self.MaaManager.accomplish.connect(
lambda: self.maa_ender("日常代理_结束")
lambda: self.maa_ender("自动代理_结束")
)
self.check_start.setEnabled(False)
self.run_now.clicked.disconnect()
self.run_now.setText("结束运行")
self.run_now.clicked.connect(lambda: self.maa_ender("日常代理_结束"))
self.run_now.clicked.connect(lambda: self.maa_ender("自动代理_结束"))
elif mode == "人工排查_开始":
self.MaaManager.accomplish.connect(
@@ -660,12 +511,12 @@ class Main(QWidget):
self.update_user_info("editable")
if mode == "日常代理_结束":
if mode == "自动代理_结束":
self.check_start.setEnabled(True)
self.run_now.clicked.disconnect()
self.run_now.setText("立即执行")
self.run_now.clicked.connect(lambda: self.maa_starter("日常代理"))
self.run_now.clicked.connect(lambda: self.maa_starter("自动代理"))
elif mode == "人工排查_结束":

View File

@@ -25,6 +25,7 @@ v4.2
作者DLmaster_361
"""
from loguru import logger
from PySide6.QtWidgets import (
QApplication,
QSystemTrayIcon,
@@ -41,18 +42,17 @@ from qfluentwidgets import (
Theme,
MSFluentWindow,
NavigationItemPosition,
qconfig,
)
from PySide6.QtUiTools import QUiLoader
from PySide6.QtGui import QIcon, QCloseEvent
from PySide6 import QtCore
uiLoader = QUiLoader()
from app import AppConfig
from app.core import AppConfig, TaskManager, MainTimer, MainInfoBar
from app.services import Notification, CryptoHandler, SystemHandler
from .setting import Setting
from .member_manager import MemberManager
from .queue_manager import QueueManager
from .dispatch_center import DispatchCenter
class AUTO_MAA(MSFluentWindow):
@@ -81,10 +81,16 @@ class AUTO_MAA(MSFluentWindow):
self.splashScreen = SplashScreen(self.windowIcon(), self)
self.show_ui("显示主窗口", if_quick=True)
MainInfoBar.parent = self
self.task_manager = TaskManager(self.config, self.notify)
self.main_timer = MainTimer(self.config, self.system, self.task_manager, self)
# 创建主窗口
self.setting = Setting(self.config, self.notify, self.crypto, self.system, self)
self.member_manager = MemberManager(self.config, self.notify, self.crypto, self)
self.queue_manager = QueueManager(self.config, self.notify, self)
self.dispatch_center = DispatchCenter(self.config, self.task_manager, self)
self.addSubInterface(
self.setting,
@@ -107,9 +113,31 @@ class AUTO_MAA(MSFluentWindow):
FluentIcon.BOOK_SHELF,
NavigationItemPosition.TOP,
)
self.addSubInterface(
self.dispatch_center,
FluentIcon.IOT,
"调度中心",
FluentIcon.IOT,
NavigationItemPosition.TOP,
)
self.stackedWidget.currentChanged.connect(
lambda index: (self.member_manager.refresh() if index == 1 else None)
)
self.stackedWidget.currentChanged.connect(
lambda index: self.queue_manager.refresh() if index == 2 else None
)
self.stackedWidget.currentChanged.connect(
lambda index: (
self.dispatch_center.pivot.setCurrentItem("主调度台")
if index == 3
else None
)
)
self.stackedWidget.currentChanged.connect(
lambda index: (
self.dispatch_center.update_top_bar() if index == 3 else None
)
)
# 创建系统托盘及其菜单
self.tray = QSystemTrayIcon(
@@ -134,8 +162,8 @@ class AUTO_MAA(MSFluentWindow):
# [
# Action(
# FluentIcon.PLAY,
# "运行日常代理",
# triggered=lambda: self.start_task("日常代理"),
# "运行自动代理",
# triggered=lambda: self.start_task("自动代理"),
# ),
# Action(
# FluentIcon.PLAY,
@@ -156,6 +184,7 @@ class AUTO_MAA(MSFluentWindow):
self.tray.setContextMenu(self.tray_menu)
self.tray.activated.connect(self.on_tray_activated)
self.task_manager.create_gui.connect(self.dispatch_center.add_board)
self.setting.ui.card_IfShowTray.checkedChanged.connect(
lambda: self.show_ui("配置托盘")
)
@@ -166,22 +195,17 @@ class AUTO_MAA(MSFluentWindow):
def start_up_task(self) -> None:
"""启动时任务"""
# 加载配置
qconfig.load(self.config.config_path, self.config.global_config)
# 检查密码
self.setting.check_PASSWORD()
# 检查更新
if self.config.global_config.get(self.config.global_config.update_IfAutoUpdate):
result = self.setting.check_update()
result = self.setting.get_update_info()
if result == "已是最新版本~":
InfoBar.success(
title="更新检查",
content=result,
orient=QtCore.Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=3000,
parent=self,
)
MainInfoBar.push_info_bar("success", "更新检查", result, 3000)
else:
info = InfoBar.info(
title="更新检查",
@@ -193,9 +217,7 @@ class AUTO_MAA(MSFluentWindow):
parent=self,
)
Up = PushButton("更新")
Up.clicked.connect(
lambda: self.setting.check_version(if_question=False)
)
Up.clicked.connect(lambda: self.setting.get_update(if_question=False))
Up.clicked.connect(info.close)
info.addWidget(Up)
info.show()
@@ -234,7 +256,7 @@ class AUTO_MAA(MSFluentWindow):
# """中止当前任务"""
# if self.main.MaaManager.isRunning():
# if (
# self.main.MaaManager.mode == "日常代理"
# self.main.MaaManager.mode == "自动代理"
# or self.main.MaaManager.mode == "人工排查"
# ):
# self.main.maa_ender(f"{self.main.MaaManager.mode}_结束")

View File

@@ -24,7 +24,7 @@ AUTO_MAA脚本管理界面
v4.2
作者DLmaster_361
"""
from loguru import logger
from PySide6.QtWidgets import (
QWidget,
QFileDialog,
@@ -49,17 +49,15 @@ from qfluentwidgets import (
ExpandGroupSettingCard,
PushSettingCard,
)
from PySide6.QtUiTools import QUiLoader
from PySide6 import QtCore
from functools import partial
from pathlib import Path
from typing import List
import datetime
import json
import shutil
uiLoader = QUiLoader()
from app import AppConfig, MaaConfig
from app.core import AppConfig, MaaConfig, MainInfoBar
from app.services import Notification, CryptoHandler
from .Widget import (
InputMessageBox,
@@ -315,6 +313,15 @@ class MemberManager(QWidget):
with json_file.open("w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
def refresh(self):
"""刷新脚本实例界面"""
if len(self.member_manager.search_member()) == 0:
index = 0
else:
index = int(self.member_manager.pivot.currentRouteKey()[3:])
self.member_manager.switch_SettingBox(index)
class MemberSettingBox(QWidget):
@@ -444,7 +451,7 @@ class MaaSettingBox(QWidget):
content_widget = QWidget()
content_layout = QVBoxLayout(content_widget)
self.app_setting = self.AppSettingCard(self, self.config.maa_config)
self.app_setting = self.AppSettingCard(self, self.config, uid)
self.user_setting = self.UserSettingCard(
self, self.objectName(), self.config, self.crypto
)
@@ -461,12 +468,13 @@ class MaaSettingBox(QWidget):
class AppSettingCard(HeaderCardWidget):
def __init__(self, parent=None, maa_config: MaaConfig = None):
def __init__(self, parent=None, config: AppConfig = None, uid: int = None):
super().__init__(parent)
self.setTitle("MAA实例")
self.maa_config = maa_config
self.config = config
self.uid = uid
Layout = QVBoxLayout()
@@ -475,13 +483,13 @@ class MaaSettingBox(QWidget):
FluentIcon.EDIT,
"实例名称",
"用于标识MAA实例的名称",
self.maa_config.MaaSet_Name,
self.config.maa_config.MaaSet_Name,
)
self.card_Path = PushSettingCard(
"选择文件夹",
FluentIcon.FOLDER,
"MAA目录",
self.maa_config.get(self.maa_config.MaaSet_Path),
self.config.maa_config.get(self.config.maa_config.MaaSet_Path),
)
self.card_Set = PushSettingCard(
"设置",
@@ -489,9 +497,14 @@ class MaaSettingBox(QWidget):
"MAA全局配置",
"简洁模式下MAA将继承全局配置",
)
self.RunSet = self.RunSetSettingCard(self, self.maa_config)
self.RunSet = self.RunSetSettingCard(self, self.config.maa_config)
self.card_Path.clicked.connect(self.PathClicked)
self.config.maa_config.MaaSet_Path.valueChanged.connect(
lambda: self.card_Path.setContent(
self.config.maa_config.get(self.config.maa_config.MaaSet_Path)
)
)
Layout.addWidget(self.card_Name)
Layout.addWidget(self.card_Path)
@@ -503,9 +516,35 @@ class MaaSettingBox(QWidget):
def PathClicked(self):
folder = QFileDialog.getExistingDirectory(self, "选择MAA目录", "./")
if not folder or self.maa_config.get(self.maa_config.MaaSet_Path) == folder:
return
self.maa_config.set(self.maa_config.MaaSet_Path, folder)
if (
not folder
or self.config.maa_config.get(self.config.maa_config.MaaSet_Path)
== folder
):
logger.warning("选择MAA目录时未选择文件夹或未更改文件夹")
MainInfoBar.push_info_bar(
"warning", "警告", "未选择文件夹或未更改文件夹", 5000
)
return None
elif (
not (Path(folder) / "config/gui.json").exists()
or not (Path(folder) / "MAA.exe").exists()
):
logger.warning("选择MAA目录时未找到MAA程序或配置文件")
MainInfoBar.push_info_bar(
"warning", "警告", "未找到MAA程序或配置文件", 5000
)
return None
(self.config.app_path / f"config/MaaConfig/脚本_{self.uid}/Default").mkdir(
parents=True, exist_ok=True
)
shutil.copy(
Path(folder) / "config/gui.json",
self.config.app_path
/ f"config/MaaConfig/脚本_{self.uid}/Default/gui.json",
)
self.config.maa_config.set(self.config.maa_config.MaaSet_Path, folder)
self.card_Path.setContent(folder)
class RunSetSettingCard(ExpandGroupSettingCard):
@@ -534,7 +573,7 @@ class MaaSettingBox(QWidget):
self.RoutineTimeLimit = SpinBoxSettingCard(
(1, 1024),
FluentIcon.PAGE_RIGHT,
"日常代理超时限制",
"自动代理超时限制",
"MAA日志无变化时间超过该阈值视为超时单位为分钟",
self.maa_config.RunSet_RoutineTimeLimit,
)

View File

@@ -39,6 +39,7 @@ from qfluentwidgets import (
FluentIcon,
MessageBox,
HeaderCardWidget,
TextBrowser,
CommandBar,
setTheme,
Theme,
@@ -52,7 +53,7 @@ import shutil
uiLoader = QUiLoader()
from app import AppConfig, QueueConfig
from app.core import AppConfig, QueueConfig
from app.services import Notification
from .Widget import (
LineEditSettingCard,
@@ -143,9 +144,9 @@ class QueueManager(QWidget):
if choice.exec():
queue_list = self.queue_manager.search_queue()
move_list = [_ for _ in queue_list if int(_[0][3:]) > int(name[3:])]
move_list = [_ for _ in queue_list if int(_[0][5:]) > int(name[5:])]
index = max(int(name[3:]) - 1, 1)
index = max(int(name[5:]) - 1, 1)
self.queue_manager.clear_SettingBox()
@@ -249,7 +250,7 @@ class QueueSettingBox(QWidget):
self.Layout.setContentsMargins(0, 0, 0, 0)
self.pivot.currentItemChanged.connect(
lambda index: self.switch_SettingBox(int(index[5:]), if_chang_pivot=False)
lambda index: self.switch_SettingBox(int(index[5:]), if_change_pivot=False)
)
self.show_SettingBox(1)
@@ -271,7 +272,7 @@ class QueueSettingBox(QWidget):
self.switch_SettingBox(index)
def switch_SettingBox(self, index: int, if_chang_pivot: bool = True) -> None:
def switch_SettingBox(self, index: int, if_change_pivot: bool = True) -> None:
"""切换到指定的子界面"""
queue_list = self.search_queue()
@@ -288,7 +289,7 @@ class QueueSettingBox(QWidget):
self.config.queue_config,
)
if if_chang_pivot:
if if_change_pivot:
self.pivot.setCurrentItem(self.script_list[index - 1].objectName())
self.stackedWidget.setCurrentWidget(self.script_list[index - 1])
@@ -355,10 +356,12 @@ class QueueMemberSettingBox(QWidget):
self.queue_set = self.QueueSetSettingCard(self, self.config.queue_config)
self.time = self.TimeSettingCard(self, self.config.queue_config)
self.task = self.TaskSettingCard(self, self.config)
self.history = self.HistoryCard(self, self.config, f"调度队列_{uid}")
content_layout.addWidget(self.queue_set)
content_layout.addWidget(self.time)
content_layout.addWidget(self.task)
content_layout.addWidget(self.history)
content_layout.addStretch(1)
scrollArea.setWidget(content_widget)
@@ -498,36 +501,6 @@ class QueueMemberSettingBox(QWidget):
self.viewLayout.addLayout(Layout)
class QueueSetSettingCard(HeaderCardWidget):
def __init__(self, parent=None, queue_config: QueueConfig = None):
super().__init__(parent)
self.setTitle("队列设置")
self.queue_config = queue_config
Layout = QVBoxLayout()
self.card_Name = LineEditSettingCard(
"请输入调度队列名称",
FluentIcon.EDIT,
"调度队列名称",
"用于标识调度队列的名称",
self.queue_config.queueSet_Name,
)
self.card_Enable = SwitchSettingCard(
FluentIcon.HOME,
"状态",
"调度队列状态",
self.queue_config.queueSet_Enabled,
)
Layout.addWidget(self.card_Name)
Layout.addWidget(self.card_Enable)
self.viewLayout.addLayout(Layout)
class TaskSettingCard(HeaderCardWidget):
def __init__(self, parent=None, config: AppConfig = None):
@@ -656,3 +629,18 @@ class QueueMemberSettingBox(QWidget):
member_list_text.append(subdir.name)
return [member_list_name, member_list_text]
class HistoryCard(HeaderCardWidget):
def __init__(self, parent=None, config: AppConfig = None, name: str = None):
super().__init__(parent)
self.setTitle("历史运行记录")
self.config = config
self.text = TextBrowser()
self.text.setMinimumHeight(300)
history = self.config.get_history(name)
self.text.setPlainText(history["History"])
self.viewLayout.addWidget(self.text)

View File

@@ -36,9 +36,8 @@ from qfluentwidgets import (
setTheme,
Theme,
MessageBox,
Dialog,
HeaderCardWidget,
InfoBar,
InfoBarPosition,
SwitchSettingCard,
ExpandGroupSettingCard,
PushSettingCard,
@@ -52,7 +51,7 @@ import requests
uiLoader = QUiLoader()
from app import AppConfig
from app.core import AppConfig, MainInfoBar
from app.services import Notification, CryptoHandler, SystemHandler
from app.utils import Updater, version_text
from .Widget import InputMessageBox, LineEditSettingCard
@@ -98,7 +97,7 @@ class Setting(QWidget):
self.function.card_IfAllowSleep.checkedChanged.connect(self.system.set_Sleep)
self.start.card_IfSelfStart.checkedChanged.connect(self.system.set_SelfStart)
self.security.card_changePASSWORD.clicked.connect(self.change_PASSWORD)
self.updater.card_CheckUpdate.clicked.connect(self.check_version)
self.updater.card_CheckUpdate.clicked.connect(self.get_update)
self.other.card_Tips.clicked.connect(self.show_tips)
content_layout.addWidget(self.function)
@@ -258,7 +257,7 @@ class Setting(QWidget):
if choice.exec():
break
def check_update(self) -> str:
def get_update_info(self) -> str:
"""检查主程序版本更新,返回更新信息"""
# 从本地版本信息文件获取当前版本信息
@@ -294,7 +293,7 @@ class Setting(QWidget):
else:
return "已是最新版本~"
def check_version(self, if_question: bool = True) -> None:
def get_update(self, if_question: bool = True) -> None:
"""检查版本更新,调起文件下载进程"""
# 从本地版本信息文件获取当前版本信息
@@ -387,15 +386,7 @@ class Setting(QWidget):
# 无版本更新
else:
InfoBar.success(
title="更新检查",
content="已是最新版本~",
orient=QtCore.Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=3000,
parent=self,
)
MainInfoBar.push_info_bar("success", "更新检查", "已是最新版本~", 3000)
def update_main(self):
"""更新主程序"""
@@ -411,7 +402,7 @@ class Setting(QWidget):
def show_tips(self):
"""显示小贴士"""
choice = MessageBox("小贴士", "这里什么都没有~", self)
choice = Dialog("小贴士", "这里什么都没有~", self)
choice.cancelButton.hide()
choice.buttonLayout.insertStretch(1)
if choice.exec():