From 1feb0cf83f8e4a8581bb5aa8860f389794b3cfc7 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Wed, 5 Mar 2025 15:11:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(serices):=20=E4=BF=AE=E5=A4=8D=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=9C=8D=E5=8A=A1=E4=BD=BF=E7=94=A8InfoBar=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E6=97=B6=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/timer.py | 5 +---- app/services/notification.py | 28 +++++++++++++++++++++------- app/ui/main_window.py | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/core/timer.py b/app/core/timer.py index 97357b2..449ceba 100644 --- a/app/core/timer.py +++ b/app/core/timer.py @@ -39,10 +39,7 @@ from app.services import System class _MainTimer(QWidget): - def __init__( - self, - parent=None, - ): + def __init__(self, parent=None): super().__init__(parent) self.if_FailSafeException = False diff --git a/app/services/notification.py b/app/services/notification.py index 8d2fcca..a8eeda1 100644 --- a/app/services/notification.py +++ b/app/services/notification.py @@ -24,6 +24,9 @@ AUTO_MAA通知服务 v4.2 作者:DLmaster_361 """ + +from PySide6.QtWidgets import QWidget +from PySide6.QtCore import Signal import requests from loguru import logger from plyer import notification @@ -36,11 +39,16 @@ from email.utils import formataddr from serverchan_sdk import sc_send -from app.core import Config, MainInfoBar +from app.core import Config from app.services.security import Crypto -class Notification: +class Notification(QWidget): + + push_info_bar = Signal(str, str, str, int) + + def __init__(self, parent=None): + super().__init__(parent) def push_plyer(self, title, message, ticker, t): """推送系统通知""" @@ -89,6 +97,12 @@ class Notification: logger.error( "请正确设置邮件通知的SMTP服务器地址、授权码、发件人地址和收件人地址" ) + self.push_info_bar.emit( + "error", + "邮件通知推送异常", + "请正确设置邮件通知的SMTP服务器地址、授权码、发件人地址和收件人地址", + -1, + ) return None try: @@ -139,7 +153,7 @@ class Notification: logger.success("邮件发送成功") except Exception as e: logger.error(f"发送邮件时出错:\n{e}") - MainInfoBar.push_info_bar("error", "发送邮件时出错", f"{e}", -1) + self.push_info_bar.emit("error", "发送邮件时出错", f"{e}", -1) def ServerChanPush(self, title, content): """使用Server酱推送通知""" @@ -168,7 +182,7 @@ class Notification: else: option["tags"] = "" logger.warning("请正确设置Auto_MAA中ServerChan的Tag。") - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "warning", "Server酱通知推送异常", "请正确设置Auto_MAA中ServerChan的Tag。", @@ -180,7 +194,7 @@ class Notification: else: option["channel"] = "" logger.warning("请正确设置Auto_MAA中ServerChan的Channel。") - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "warning", "Server酱通知推送异常", "请正确设置Auto_MAA中ServerChan的Channel。", @@ -194,7 +208,7 @@ class Notification: else: logger.info("Server酱推送通知失败") logger.error(response) - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "error", "Server酱通知推送失败", f'使用Server酱推送通知时出错:\n{response["data"]['error']}', @@ -219,7 +233,7 @@ class Notification: else: logger.info("企业微信群机器人推送通知失败") logger.error(response.json()) - MainInfoBar.push_info_bar( + self.push_info_bar.emit( "error", "企业微信群机器人通知推送失败", f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}', diff --git a/app/ui/main_window.py b/app/ui/main_window.py index fc2b2ae..fb097fa 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -189,6 +189,7 @@ class AUTO_MAA(MSFluentWindow): TaskManager.create_gui.connect(self.dispatch_center.add_board) TaskManager.connect_gui.connect(self.dispatch_center.connect_main_board) + Notify.push_info_bar.connect(MainInfoBar.push_info_bar) self.setting.ui.card_IfShowTray.checkedChanged.connect( lambda: self.show_ui("配置托盘") )