From 040f40d94be001e7388dfd1aee8283b98bf7b26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sat, 8 Feb 2025 22:25:00 +0800 Subject: [PATCH] fix notify bug --- .../Model/BaseNotificationData.cs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/BetterGenshinImpact/Service/Notification/Model/BaseNotificationData.cs b/BetterGenshinImpact/Service/Notification/Model/BaseNotificationData.cs index 70f1ad97..1f19ef13 100644 --- a/BetterGenshinImpact/Service/Notification/Model/BaseNotificationData.cs +++ b/BetterGenshinImpact/Service/Notification/Model/BaseNotificationData.cs @@ -5,6 +5,7 @@ using System.Drawing; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.Service.Notification.Converter; +using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.Service.Notification.Model; @@ -21,13 +22,13 @@ public class BaseNotificationData /// [JsonConverter(typeof(JsonStringEnumConverter))] public NotificationEventResult Result { get; set; } - + /// /// 事件触发时间 /// [JsonConverter(typeof(DateTimeJsonConverter))] public DateTime Timestamp { get; set; } = DateTime.Now; - + /// /// 事件触发时的截图 /// @@ -46,14 +47,28 @@ public class BaseNotificationData public void Send() { - if (TaskContext.Instance().Config.NotificationConfig.IncludeScreenShot) + try { - Screenshot = (Bitmap)TaskControl.CaptureToRectArea().SrcBitmap.Clone(); + if (TaskContext.Instance().Config.NotificationConfig.IncludeScreenShot) + { + Screenshot = (Bitmap)TaskControl.CaptureToRectArea().SrcBitmap.Clone(); + } + } + catch (Exception e) + { + TaskControl.Logger.LogDebug(e, "补充通知截图失败"); + } + + try + { + NotificationService.Instance().NotifyAllNotifiers(this); + } + catch (Exception e) + { + TaskControl.Logger.LogDebug(e, "发送通知失败"); } - - NotificationService.Instance().NotifyAllNotifiers(this); } - + public void Send(string message) { Message = message;