diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 180836e..08b89ca 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -70,7 +70,7 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Built with pyinstaller run: | - pyinstaller -F --version-file res/info.txt -w --icon=res/AUTO_MAA.ico AUTO_MAA.py + pyinstaller -F --version-file res/info.txt -w --icon=res/AUTO_MAA.ico AUTO_MAA.py --hidden-import plyer.platforms.win.notification - name: Read version id: read_version run: | diff --git a/AUTO_MAA.py b/AUTO_MAA.py index d77d075..212c2ae 100644 --- a/AUTO_MAA.py +++ b/AUTO_MAA.py @@ -39,6 +39,7 @@ from PySide6.QtUiTools import QUiLoader from PySide6.QtGui import QIcon from PySide6 import QtCore from functools import partial +from plyer import notification import sqlite3 import json import datetime @@ -62,6 +63,7 @@ uiLoader = QUiLoader() class MaaRunner(QtCore.QThread): question = QtCore.Signal() + push_notification = QtCore.Signal(str, str, str, int) update_gui = QtCore.Signal(str, str, str, str, str) update_user_info = QtCore.Signal(list, list, list, list, list) accomplish = QtCore.Signal() @@ -125,10 +127,10 @@ class MaaRunner(QtCore.QThread): continue # 配置MAA self.set_maa(mode_book[j], uid) - # 创建MAA任务 - maa = subprocess.Popen([self.maa_path]) # 记录当前时间 start_time = datetime.datetime.now() + # 创建MAA任务 + maa = subprocess.Popen([self.maa_path]) # 记录是否超时的标记 self.if_time_out = False # 更新运行信息 @@ -227,6 +229,19 @@ class MaaRunner(QtCore.QThread): result, ) os.system("taskkill /F /T /PID " + str(maa.pid)) + self.push_notification.emit( + "用户日常代理出现异常!", + "用户 " + + self.data[uid][0].replace("_", " 今天的") + + "的" + + mode_book[j][5:7] + + "部分出现一次异常", + self.data[uid][0].replace("_", " ") + + "的" + + mode_book[j][5:7] + + "出现异常", + 1, + ) if self.if_run: time.sleep(10) break @@ -235,6 +250,14 @@ class MaaRunner(QtCore.QThread): self.data[uid][2] -= 1 self.data[uid][12] += 1 over_uid.append(uid) + self.push_notification.emit( + "成功完成一个日常代理任务!", + "已完成用户 " + + self.data[uid][0].replace("_", " 今天的") + + "任务", + "已完成 " + self.data[uid][0].replace("_", " 的"), + 3, + ) break if not (run_book[0] and run_book[1]): error_uid.append(uid) @@ -258,10 +281,10 @@ class MaaRunner(QtCore.QThread): if_strat_app = False else: self.set_maa("人工排查_仅切换账号", uid) - # 创建MAA任务 - maa = subprocess.Popen([self.maa_path]) # 记录当前时间 start_time = datetime.datetime.now() + # 创建MAA任务 + maa = subprocess.Popen([self.maa_path]) # 更新运行信息 wait_uid = [ _ for _ in all_uid if (not _ in over_uid + error_uid + [uid]) @@ -424,6 +447,19 @@ class MaaRunner(QtCore.QThread): with open(self.app_path + "/log.txt", "r", encoding="utf-8") as f: end_log = f.read() self.update_gui.emit("", "", "", "", end_log) + # 推送windows通知 + self.push_notification.emit( + self.mode[2:4] + "任务已完成!", + "已完成用户数:" + + str(len(over_uid)) + + ",未完成用户数:" + + str(len(error_uid) + len(wait_uid)), + "已完成用户数:" + + str(len(over_uid)) + + ",未完成用户数:" + + str(len(error_uid) + len(wait_uid)), + 10, + ) self.accomplish.emit() self.if_run = False @@ -992,6 +1028,7 @@ class Main(QWidget): self.MaaRunner.question.connect(lambda: self.read("question_runner")) self.MaaRunner.update_gui.connect(self.update_board) self.MaaRunner.update_user_info.connect(self.change_user_info) + self.MaaRunner.push_notification.connect(self.push_notification) self.MaaRunner.accomplish.connect(self.routine_ender) self.MainTimer = MainTimer(self.config) @@ -1614,6 +1651,18 @@ class Main(QWidget): self.MainTimer.is_maa_run = True self.MaaRunner.start() + def push_notification(self, title, message, ticker, t): + """推送系统通知""" + notification.notify( + title=title, + message=message, + app_name="AUTO_MAA", + app_icon=self.app_path + "/res/AUTO_MAA.ico", + timeout=t, + ticker=ticker, + toast=True, + ) + def give_config(self): """同步配置文件到子线程""" self.MainTimer.config = self.config diff --git a/requirements.txt b/requirements.txt index ec904f9..2f0e33d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +plyer PySide6 pycryptodome pyinstaller \ No newline at end of file diff --git a/toexe.py b/toexe.py index 3d57ebd..7962c51 100644 --- a/toexe.py +++ b/toexe.py @@ -21,5 +21,5 @@ import os os.system( - "pyinstaller -F --version-file res/info.txt -w --icon=res/AUTO_MAA.ico AUTO_MAA.py" + "pyinstaller -F --version-file res/info.txt -w --icon=res/AUTO_MAA.ico AUTO_MAA.py --hidden-import plyer.platforms.win.notification" ) diff --git a/更新说明.txt b/更新说明.txt index d0eefe1..87720d0 100644 --- a/更新说明.txt +++ b/更新说明.txt @@ -1,6 +1,7 @@ v3.1.3_beta ## 新增功能 - MAA设置逻辑优化 +- 新增windows通知功能 ## 修复BUG - accomplish槽函数绑定逻辑修复 ## 程序优化