From 1aa4da1adf1656b7e50f99eb28bc16e8a9711030 Mon Sep 17 00:00:00 2001 From: DLmaster361 Date: Mon, 9 Jun 2025 23:43:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-app-test.yml | 213 --------------------------- .github/workflows/build-app.yml | 162 ++++++++++++++++++-- app/core/config.py | 29 +++- app/core/task_manager.py | 3 + app/services/system.py | 2 + app/ui/Widget.py | 2 +- app/ui/main_window.py | 38 +++++ app/ui/setting.py | 7 +- app/utils/package.py | 2 +- main.py | 17 +++ resources/version.json | 3 +- 11 files changed, 241 insertions(+), 237 deletions(-) delete mode 100644 .github/workflows/build-app-test.yml diff --git a/.github/workflows/build-app-test.yml b/.github/workflows/build-app-test.yml deleted file mode 100644 index 8dbeee0..0000000 --- a/.github/workflows/build-app-test.yml +++ /dev/null @@ -1,213 +0,0 @@ -# AUTO_MAA:A MAA Multi Account Management and Automation Tool -# Copyright © 2024-2025 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 . - -# Contact: DLmaster_361@163.com - -name: Build AUTO_MAA Test - -on: - workflow_dispatch: - -permissions: - contents: write - actions: write - -jobs: - - pre_check: - name: Pre Checks - runs-on: ubuntu-latest - - steps: - - name: Repo Check - id: repo_check - run: | - if [[ "$GITHUB_REPOSITORY" != "DLmaster361/AUTO_MAA" ]]; then - echo "When forking this repository to make your own builds, you have to adjust this check." - exit 1 - fi - exit 0 - - build_AUTO_MAA: - runs-on: windows-latest - needs: pre_check - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - pip install -r requirements.txt - - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - - name: Get version - id: get_version - run: | - $version = (Get-Content resources/version.json | ConvertFrom-Json).main_version - echo "main_version=$version" >> $env:GITHUB_OUTPUT - - - name: Nuitka build main program - uses: Nuitka/Nuitka-Action@main - with: - script-name: main.py - mode: app - enable-plugins: pyside6 - onefile-tempdir-spec: "{TEMP}/AUTO_MAA" - windows-console-mode: disable - windows-icon-from-ico: resources/icons/AUTO_MAA.ico - company-name: AUTO_MAA Team - product-name: AUTO_MAA - file-version: ${{ steps.get_version.outputs.main_version }} - product-version: ${{ steps.get_version.outputs.main_version }} - file-description: AUTO_MAA Component - copyright: Copyright © 2024-2025 DLmaster361 - assume-yes-for-downloads: true - output-file: AUTO_MAA - output-dir: AUTO_MAA - - - name: Upload unsigned main program - id: upload-unsigned-main-program - uses: actions/upload-artifact@v4 - with: - name: AUTO_MAA - path: AUTO_MAA/AUTO_MAA.exe - - - name: Sign main program - id: sign_main_program - uses: signpath/github-action-submit-signing-request@v1.2 - with: - api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' - organization-id: '787a1d5f-6177-4f30-9559-d2646473584a' - project-slug: 'AUTO_MAA_' - signing-policy-slug: 'test-signing' - artifact-configuration-slug: "AUTO_MAA" - github-artifact-id: '${{ steps.upload-unsigned-main-program.outputs.artifact-id }}' - wait-for-completion: true - output-artifact-directory: 'AUTO_MAA' - - - name: Add other resources - shell: pwsh - run: | - $root = "${{ github.workspace }}" - $ver = "${{ steps.get_version.outputs.main_version }}" - Copy-Item "$root/app" "$root/AUTO_MAA/app" -Recurse - Copy-Item "$root/resources" "$root/AUTO_MAA/resources" -Recurse - Copy-Item "$root/main.py" "$root/AUTO_MAA/" - Copy-Item "$root/requirements.txt" "$root/AUTO_MAA/" - Copy-Item "$root/README.md" "$root/AUTO_MAA/" - Copy-Item "$root/LICENSE" "$root/AUTO_MAA/" - - - name: Create Inno Setup script - shell: pwsh - run: | - $root = "${{ github.workspace }}" - $ver = "${{ steps.get_version.outputs.main_version }}" - $iss = Get-Content "$root/app/utils/AUTO_MAA.iss" -Raw - $iss = $iss -replace '#define MyAppVersion ""', "#define MyAppVersion `"$ver`"" - $iss = $iss -replace '#define MyAppPath ""', "#define MyAppPath `"$root/AUTO_MAA`"" - $iss = $iss -replace '#define OutputDir ""', "#define OutputDir `"$root`"" - Set-Content -Path "$root/AUTO_MAA.iss" -Value $iss - - - name: Build setup program - uses: Minionguyjpro/Inno-Setup-Action@v1.2.5 - with: - path: AUTO_MAA.iss - - - name: Upload unsigned setup program - id: upload-unsigned-setup-program - uses: actions/upload-artifact@v4 - with: - name: AUTO_MAA-Setup - path: AUTO_MAA-Setup.exe - - - name: Sign setup program - id: sign_setup_program - uses: signpath/github-action-submit-signing-request@v1.2 - with: - api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' - organization-id: '787a1d5f-6177-4f30-9559-d2646473584a' - project-slug: 'AUTO_MAA_' - signing-policy-slug: 'test-signing' - artifact-configuration-slug: "AUTO_MAA-Setup" - github-artifact-id: '${{ steps.upload-unsigned-setup-program.outputs.artifact-id }}' - wait-for-completion: true - output-artifact-directory: 'AUTO_MAA_Setup' - - - name: Compress setup exe - shell: pwsh - run: Compress-Archive -Path AUTO_MAA_Setup/* -DestinationPath AUTO_MAA_${{ steps.get_version.outputs.main_version }}.zip - - - name: Generate version info - shell: python - run: | - import json - from pathlib import Path - def version_text(version_numb): - while len(version_numb) < 4: - version_numb.append(0) - if version_numb[3] == 0: - return f"v{'.'.join(str(_) for _ in version_numb[0:3])}" - else: - return f"v{'.'.join(str(_) for _ in version_numb[0:3])}-beta.{version_numb[3]}" - def version_info_markdown(info): - version_info = "" - for key, value in info.items(): - version_info += f"## {key}\n" - for v in value: - version_info += f"- {v}\n" - return version_info - root_path = Path(".") - version = json.loads((root_path / "resources/version.json").read_text(encoding="utf-8")) - main_version_numb = list(map(int, version["main_version"].split("."))) - all_version_info = {} - for v_i in version["version_info"].values(): - for key, value in v_i.items(): - if key in all_version_info: - all_version_info[key] += value.copy() - else: - all_version_info[key] = value.copy() - (root_path / "version_info.txt").write_text( - f"{version_text(main_version_numb)}\n\n\n{version_info_markdown(all_version_info)}", - encoding="utf-8", - ) - - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: AUTO_MAA_${{ steps.get_version.outputs.main_version }} - path: AUTO_MAA_${{ steps.get_version.outputs.main_version }}.zip - - - name: Upload Version_Info Artifact - uses: actions/upload-artifact@v4 - with: - name: version_info - path: version_info.txt \ No newline at end of file diff --git a/.github/workflows/build-app.yml b/.github/workflows/build-app.yml index 575e65c..8bacf40 100644 --- a/.github/workflows/build-app.yml +++ b/.github/workflows/build-app.yml @@ -28,9 +28,11 @@ permissions: actions: write jobs: + pre_check: name: Pre Checks runs-on: ubuntu-latest + steps: - name: Repo Check id: repo_check @@ -40,67 +42,198 @@ jobs: exit 1 fi exit 0 + build_AUTO_MAA: runs-on: windows-latest needs: pre_check + steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Python 3.12 + + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.12" + python-version: '3.12' + - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest pip install -r requirements.txt - choco install innosetup - echo "C:\Program Files (x86)\Inno Setup 6" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Package - id: package + + - name: Get version + id: get_version run: | - copy app\utils\package.py .\ - python package.py - - name: Read version - id: read_version + $version = (Get-Content resources/version.json | ConvertFrom-Json).main_version + echo "main_version=$version" >> $env:GITHUB_OUTPUT + + - name: Nuitka build main program + uses: Nuitka/Nuitka-Action@main + with: + script-name: main.py + mode: app + enable-plugins: pyside6 + onefile-tempdir-spec: "{TEMP}/AUTO_MAA" + windows-console-mode: attach + windows-icon-from-ico: resources/icons/AUTO_MAA.ico + company-name: AUTO_MAA Team + product-name: AUTO_MAA + file-version: ${{ steps.get_version.outputs.main_version }} + product-version: ${{ steps.get_version.outputs.main_version }} + file-description: AUTO_MAA Component + copyright: Copyright © 2024-2025 DLmaster361 + assume-yes-for-downloads: true + output-file: AUTO_MAA + output-dir: AUTO_MAA + + - name: Upload unsigned main program + id: upload-unsigned-main-program + uses: actions/upload-artifact@v4 + with: + name: AUTO_MAA + path: AUTO_MAA/AUTO_MAA.exe + + - name: Sign main program + id: sign_main_program + uses: signpath/github-action-submit-signing-request@v1.2 + with: + api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' + organization-id: '787a1d5f-6177-4f30-9559-d2646473584a' + project-slug: 'AUTO_MAA_' + signing-policy-slug: 'test-signing' + artifact-configuration-slug: "AUTO_MAA" + github-artifact-id: '${{ steps.upload-unsigned-main-program.outputs.artifact-id }}' + wait-for-completion: true + output-artifact-directory: 'AUTO_MAA' + + - name: Add other resources + shell: pwsh run: | - $MAIN_VERSION=(Get-Content -Path "version_info.txt" -TotalCount 1).Trim() - "AUTO_MAA_version=$MAIN_VERSION" | Out-File -FilePath $env:GITHUB_ENV -Append + $root = "${{ github.workspace }}" + $ver = "${{ steps.get_version.outputs.main_version }}" + Copy-Item "$root/app" "$root/AUTO_MAA/app" -Recurse + Copy-Item "$root/resources" "$root/AUTO_MAA/resources" -Recurse + Copy-Item "$root/main.py" "$root/AUTO_MAA/" + Copy-Item "$root/requirements.txt" "$root/AUTO_MAA/" + Copy-Item "$root/README.md" "$root/AUTO_MAA/" + Copy-Item "$root/LICENSE" "$root/AUTO_MAA/" + + - name: Create Inno Setup script + shell: pwsh + run: | + $root = "${{ github.workspace }}" + $ver = "${{ steps.get_version.outputs.main_version }}" + $iss = Get-Content "$root/app/utils/AUTO_MAA.iss" -Raw + $iss = $iss -replace '#define MyAppVersion ""', "#define MyAppVersion `"$ver`"" + $iss = $iss -replace '#define MyAppPath ""', "#define MyAppPath `"$root/AUTO_MAA`"" + $iss = $iss -replace '#define OutputDir ""', "#define OutputDir `"$root`"" + Set-Content -Path "$root/AUTO_MAA.iss" -Value $iss + + - name: Build setup program + uses: Minionguyjpro/Inno-Setup-Action@v1.2.5 + with: + path: AUTO_MAA.iss + + - name: Upload unsigned setup program + id: upload-unsigned-setup-program + uses: actions/upload-artifact@v4 + with: + name: AUTO_MAA-Setup + path: AUTO_MAA-Setup.exe + + - name: Sign setup program + id: sign_setup_program + uses: signpath/github-action-submit-signing-request@v1.2 + with: + api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' + organization-id: '787a1d5f-6177-4f30-9559-d2646473584a' + project-slug: 'AUTO_MAA_' + signing-policy-slug: 'test-signing' + artifact-configuration-slug: "AUTO_MAA-Setup" + github-artifact-id: '${{ steps.upload-unsigned-setup-program.outputs.artifact-id }}' + wait-for-completion: true + output-artifact-directory: 'AUTO_MAA_Setup' + + - name: Compress setup exe + shell: pwsh + run: Compress-Archive -Path AUTO_MAA_Setup/* -DestinationPath AUTO_MAA_${{ steps.get_version.outputs.main_version }}.zip + + - name: Generate version info + shell: python + run: | + import json + from pathlib import Path + def version_text(version_numb): + while len(version_numb) < 4: + version_numb.append(0) + if version_numb[3] == 0: + return f"v{'.'.join(str(_) for _ in version_numb[0:3])}" + else: + return f"v{'.'.join(str(_) for _ in version_numb[0:3])}-beta.{version_numb[3]}" + def version_info_markdown(info): + version_info = "" + for key, value in info.items(): + version_info += f"## {key}\n" + for v in value: + version_info += f"- {v}\n" + return version_info + root_path = Path(".") + version = json.loads((root_path / "resources/version.json").read_text(encoding="utf-8")) + main_version_numb = list(map(int, version["main_version"].split("."))) + all_version_info = {} + for v_i in version["version_info"].values(): + for key, value in v_i.items(): + if key in all_version_info: + all_version_info[key] += value.copy() + else: + all_version_info[key] = value.copy() + (root_path / "version_info.txt").write_text( + f"{version_text(main_version_numb)}\n\n\n{version_info_markdown(all_version_info)}", + encoding="utf-8", + ) + - name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: AUTO_MAA_${{ env.AUTO_MAA_version }} - path: AUTO_MAA_${{ env.AUTO_MAA_version }}.zip + name: AUTO_MAA_${{ steps.get_version.outputs.main_version }} + path: AUTO_MAA_${{ steps.get_version.outputs.main_version }}.zip + - name: Upload Version_Info Artifact uses: actions/upload-artifact@v4 with: name: version_info path: version_info.txt + publish_release: name: Publish release needs: build_AUTO_MAA runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v4 + - name: Download artifacts uses: actions/download-artifact@v4 with: pattern: AUTO_MAA_* merge-multiple: true path: artifacts + - name: Download Version_Info uses: actions/download-artifact@v4 with: name: version_info path: ./ + - name: Create release id: create_release run: | @@ -122,6 +255,7 @@ jobs: gh release create "$TAGNAME" --target "main" --title "$NAME" --notes "$NOTES" $PRERELEASE_FLAG artifacts/* env: GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} + - name: Trigger MirrorChyanUploading run: | gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan diff --git a/app/core/config.py b/app/core/config.py index 00ea92d..436a4c0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -27,6 +27,7 @@ v4.3 from loguru import logger from PySide6.QtCore import Signal +import argparse import sqlite3 import json import sys @@ -614,6 +615,27 @@ class AppConfig(GlobalConfig): self.if_ignore_silence = False self.if_database_opened = False + self.search_member() + self.search_queue() + + parser = argparse.ArgumentParser( + prog="AUTO_MAA", + description="A MAA Multi Account Management and Automation Tool", + ) + parser.add_argument( + "--mode", + choices=["gui", "cli"], + default="gui", + help="使用UI界面或命令行模式运行程序", + ) + parser.add_argument( + "--config", + nargs="+", + choices=list(self.member_dict.keys()) + list(self.queue_dict.keys()), + help="指定需要运行哪些配置项", + ) + self.args = parser.parse_args() + self.initialize() def initialize(self) -> None: @@ -636,7 +658,8 @@ class AppConfig(GlobalConfig): def init_logger(self) -> None: """初始化日志记录器""" - logger.remove(0) + if self.args.mode != "cli": + logger.remove(0) logger.add( sink=self.log_path, @@ -649,10 +672,14 @@ class AppConfig(GlobalConfig): retention="1 month", compression="zip", ) + logger.info("") logger.info("===================================") logger.info("AUTO_MAA 主程序") logger.info(f"版本号: v{self.VERSION}") logger.info(f"根目录: {self.app_path}") + logger.info( + f"运行模式: {'图形化界面' if self.args.mode == 'gui' else '命令行界面'}" + ) logger.info("===================================") logger.info("日志记录器初始化完成") diff --git a/app/core/task_manager.py b/app/core/task_manager.py index 87214ff..8d205db 100644 --- a/app/core/task_manager.py +++ b/app/core/task_manager.py @@ -283,6 +283,9 @@ class _TaskManager(QObject): ) ) + if Config.args.mode == "cli" and Config.power_sign == "NoAction": + Config.set_power_sign("KillSelf") + def check_maa_version(self, v: str): """检查MAA版本""" diff --git a/app/services/system.py b/app/services/system.py index eee6a58..0f09e96 100644 --- a/app/services/system.py +++ b/app/services/system.py @@ -112,6 +112,7 @@ class _SystemHandler: Config.main_window.close() QApplication.quit() + sys.exit(0) elif sys.platform.startswith("linux"): @@ -138,6 +139,7 @@ class _SystemHandler: Config.main_window.close() QApplication.quit() + sys.exit(0) def is_startup(self) -> bool: """判断程序是否已经开机自启""" diff --git a/app/ui/Widget.py b/app/ui/Widget.py index c810ccf..3f25e88 100644 --- a/app/ui/Widget.py +++ b/app/ui/Widget.py @@ -162,7 +162,7 @@ class ProgressRingMessageBox(MessageBoxBase): super().__init__(parent) self.title = SubtitleLabel(title) - self.time = 100 + self.time = 100 if Config.args.mode == "gui" else 1 Widget = QWidget() Layout = QHBoxLayout(Widget) self.ring = ProgressRing() diff --git a/app/ui/main_window.py b/app/ui/main_window.py index 1f083b6..9069d82 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -257,6 +257,9 @@ class AUTO_MAA(MSFluentWindow): ) -> None: """配置窗口状态""" + if Config.args.mode != "gui": + return None + self.switch_theme() if mode == "显示主窗口": @@ -379,6 +382,41 @@ class AUTO_MAA(MSFluentWindow): self.titleBar.minBtn.click() + if Config.args.config: + + for config in [_ for _ in Config.args.config if _ in Config.queue_dict]: + + TaskManager.add_task( + "自动代理_新调度台", + config, + Config.queue_dict["调度队列_1"]["Config"].toDict(), + ) + + for config in [_ for _ in Config.args.config if _ in Config.member_dict]: + + TaskManager.add_task( + "自动代理_新调度台", + "自定义队列", + {"Queue": {"Member_1": config}}, + ) + + if not any( + _ in (list(Config.member_dict.keys()) + list(Config.queue_dict.keys())) + for _ in Config.args.config + ): + + logger.warning( + "当前运行模式为命令行模式,由于您使用了错误的 --config 参数进行配置,程序自动退出" + ) + System.set_power("KillSelf") + + elif Config.args.mode == "cli": + + logger.warning( + "当前运行模式为命令行模式,由于您未使用 --config 参数进行配置,程序自动退出" + ) + System.set_power("KillSelf") + def clean_old_logs(self): """ 删除超过用户设定天数的日志文件(基于目录日期) diff --git a/app/ui/setting.py b/app/ui/setting.py index 682ba7f..bec3b26 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -561,12 +561,7 @@ class Setting(QWidget): 8. AUTO_MAA 没有实时合成语音的能力,软件所有语音都存储在本地。如果听到本地不存在的语音,立即关闭扬声器,并检查是否有未知脚本在运行。 9. AUTO_MAA 不会在周六凌晨更新。如果收到更新提示,请忽略,不要查看更新内容,直到第二天天亮。 10. 用户守则仅有一页""", - "--- 标记文档中止 ---": """ -xdfv-serfcx-jiol,m: !1 $bad food of do $5b 9630-300 $daad 100-1 - -// 0 == o // - -∠( °ω°)/ """, + "--- 标记文档中止 ---": "xdfv-serfcx-jiol,m: !1 $bad food of do $5b 9630-300 $daad 100-1\n\n// 0 == o //\n\n∠( °ω°)/", }, ) cc.button_cancel.hide() diff --git a/app/utils/package.py b/app/utils/package.py index 47478d7..671f65f 100644 --- a/app/utils/package.py +++ b/app/utils/package.py @@ -71,7 +71,7 @@ if __name__ == "__main__": os.system( "powershell -Command python -m nuitka --standalone --onefile --mingw64" - " --enable-plugins=pyside6 --windows-console-mode=disable" + " --enable-plugins=pyside6 --windows-console-mode=attach" " --onefile-tempdir-spec='{TEMP}\\AUTO_MAA'" " --windows-icon-from-ico=resources\\icons\\AUTO_MAA.ico" " --company-name='AUTO_MAA Team' --product-name=AUTO_MAA" diff --git a/main.py b/main.py index 94befdc..8c208a3 100644 --- a/main.py +++ b/main.py @@ -25,6 +25,23 @@ v4.3 作者:DLmaster_361 """ +# 屏蔽广告 +import builtins + + +def no_print(*args, **kwargs): + if ( + args + and isinstance(args[0], str) + and "QFluentWidgets Pro is now released." in args[0] + ): + return + return __builtins__.print(*args, **kwargs) + + +builtins.print = no_print + + from loguru import logger from PySide6.QtWidgets import QApplication from qfluentwidgets import FluentTranslator diff --git a/resources/version.json b/resources/version.json index a92b232..ebc14eb 100644 --- a/resources/version.json +++ b/resources/version.json @@ -3,7 +3,8 @@ "version_info": { "4.3.10.2": { "新增功能": [ - "公招喜报模板优化" + "公招喜报模板优化", + "支持使用命令行调用" ], "修复BUG": [ "修复更新动作重复执行问题"