添加系统通知功能

This commit is contained in:
DLmaster
2024-10-09 14:16:37 +08:00
parent c71389fc0b
commit e50697aae1
5 changed files with 57 additions and 6 deletions

View File

@@ -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: |

View File

@@ -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

View File

@@ -1,3 +1,4 @@
plyer
PySide6
pycryptodome
pyinstaller

View File

@@ -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"
)

View File

@@ -1,6 +1,7 @@
v3.1.3_beta
## 新增功能
- MAA设置逻辑优化
- 新增windows通知功能
## 修复BUG
- accomplish槽函数绑定逻辑修复
## 程序优化