添加系统通知功能
This commit is contained in:
2
.github/workflows/python-app.yml
vendored
2
.github/workflows/python-app.yml
vendored
@@ -70,7 +70,7 @@ jobs:
|
|||||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||||
- name: Built with pyinstaller
|
- name: Built with pyinstaller
|
||||||
run: |
|
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
|
- name: Read version
|
||||||
id: read_version
|
id: read_version
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
57
AUTO_MAA.py
57
AUTO_MAA.py
@@ -39,6 +39,7 @@ from PySide6.QtUiTools import QUiLoader
|
|||||||
from PySide6.QtGui import QIcon
|
from PySide6.QtGui import QIcon
|
||||||
from PySide6 import QtCore
|
from PySide6 import QtCore
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from plyer import notification
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
@@ -62,6 +63,7 @@ uiLoader = QUiLoader()
|
|||||||
class MaaRunner(QtCore.QThread):
|
class MaaRunner(QtCore.QThread):
|
||||||
|
|
||||||
question = QtCore.Signal()
|
question = QtCore.Signal()
|
||||||
|
push_notification = QtCore.Signal(str, str, str, int)
|
||||||
update_gui = QtCore.Signal(str, str, str, str, str)
|
update_gui = QtCore.Signal(str, str, str, str, str)
|
||||||
update_user_info = QtCore.Signal(list, list, list, list, list)
|
update_user_info = QtCore.Signal(list, list, list, list, list)
|
||||||
accomplish = QtCore.Signal()
|
accomplish = QtCore.Signal()
|
||||||
@@ -125,10 +127,10 @@ class MaaRunner(QtCore.QThread):
|
|||||||
continue
|
continue
|
||||||
# 配置MAA
|
# 配置MAA
|
||||||
self.set_maa(mode_book[j], uid)
|
self.set_maa(mode_book[j], uid)
|
||||||
# 创建MAA任务
|
|
||||||
maa = subprocess.Popen([self.maa_path])
|
|
||||||
# 记录当前时间
|
# 记录当前时间
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
|
# 创建MAA任务
|
||||||
|
maa = subprocess.Popen([self.maa_path])
|
||||||
# 记录是否超时的标记
|
# 记录是否超时的标记
|
||||||
self.if_time_out = False
|
self.if_time_out = False
|
||||||
# 更新运行信息
|
# 更新运行信息
|
||||||
@@ -227,6 +229,19 @@ class MaaRunner(QtCore.QThread):
|
|||||||
result,
|
result,
|
||||||
)
|
)
|
||||||
os.system("taskkill /F /T /PID " + str(maa.pid))
|
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:
|
if self.if_run:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
break
|
break
|
||||||
@@ -235,6 +250,14 @@ class MaaRunner(QtCore.QThread):
|
|||||||
self.data[uid][2] -= 1
|
self.data[uid][2] -= 1
|
||||||
self.data[uid][12] += 1
|
self.data[uid][12] += 1
|
||||||
over_uid.append(uid)
|
over_uid.append(uid)
|
||||||
|
self.push_notification.emit(
|
||||||
|
"成功完成一个日常代理任务!",
|
||||||
|
"已完成用户 "
|
||||||
|
+ self.data[uid][0].replace("_", " 今天的")
|
||||||
|
+ "任务",
|
||||||
|
"已完成 " + self.data[uid][0].replace("_", " 的"),
|
||||||
|
3,
|
||||||
|
)
|
||||||
break
|
break
|
||||||
if not (run_book[0] and run_book[1]):
|
if not (run_book[0] and run_book[1]):
|
||||||
error_uid.append(uid)
|
error_uid.append(uid)
|
||||||
@@ -258,10 +281,10 @@ class MaaRunner(QtCore.QThread):
|
|||||||
if_strat_app = False
|
if_strat_app = False
|
||||||
else:
|
else:
|
||||||
self.set_maa("人工排查_仅切换账号", uid)
|
self.set_maa("人工排查_仅切换账号", uid)
|
||||||
# 创建MAA任务
|
|
||||||
maa = subprocess.Popen([self.maa_path])
|
|
||||||
# 记录当前时间
|
# 记录当前时间
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
|
# 创建MAA任务
|
||||||
|
maa = subprocess.Popen([self.maa_path])
|
||||||
# 更新运行信息
|
# 更新运行信息
|
||||||
wait_uid = [
|
wait_uid = [
|
||||||
_ for _ in all_uid if (not _ in over_uid + error_uid + [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:
|
with open(self.app_path + "/log.txt", "r", encoding="utf-8") as f:
|
||||||
end_log = f.read()
|
end_log = f.read()
|
||||||
self.update_gui.emit("", "", "", "", end_log)
|
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.accomplish.emit()
|
||||||
self.if_run = False
|
self.if_run = False
|
||||||
|
|
||||||
@@ -992,6 +1028,7 @@ class Main(QWidget):
|
|||||||
self.MaaRunner.question.connect(lambda: self.read("question_runner"))
|
self.MaaRunner.question.connect(lambda: self.read("question_runner"))
|
||||||
self.MaaRunner.update_gui.connect(self.update_board)
|
self.MaaRunner.update_gui.connect(self.update_board)
|
||||||
self.MaaRunner.update_user_info.connect(self.change_user_info)
|
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.MaaRunner.accomplish.connect(self.routine_ender)
|
||||||
|
|
||||||
self.MainTimer = MainTimer(self.config)
|
self.MainTimer = MainTimer(self.config)
|
||||||
@@ -1614,6 +1651,18 @@ class Main(QWidget):
|
|||||||
self.MainTimer.is_maa_run = True
|
self.MainTimer.is_maa_run = True
|
||||||
self.MaaRunner.start()
|
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):
|
def give_config(self):
|
||||||
"""同步配置文件到子线程"""
|
"""同步配置文件到子线程"""
|
||||||
self.MainTimer.config = self.config
|
self.MainTimer.config = self.config
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
plyer
|
||||||
PySide6
|
PySide6
|
||||||
pycryptodome
|
pycryptodome
|
||||||
pyinstaller
|
pyinstaller
|
||||||
2
toexe.py
2
toexe.py
@@ -21,5 +21,5 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
os.system(
|
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"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user