fix: catch error from external notifications

This commit is contained in:
Liam Sho
2023-09-17 16:48:39 +08:00
parent cd9b8a5089
commit 13a226ee75

View File

@@ -11,10 +11,12 @@
// but WITHOUT ANY WARRANTY
// </copyright>
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
using Serilog;
namespace MaaWpfGui.Services.Notification
{
@@ -22,6 +24,8 @@ namespace MaaWpfGui.Services.Notification
{
private static readonly List<Task> _taskContainers = new List<Task>();
private static readonly ILogger _logger = Log.Logger;
private static async Task SendAsync(string title, string content, bool isTest = false)
{
var enabledProvider = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationEnabled, "Off");
@@ -33,14 +37,24 @@ namespace MaaWpfGui.Services.Notification
_ => new DummyNotificationProvider(),
};
var result = await provider.SendAsync(title, content);
var result = false;
try
{
result = await provider.SendAsync(title, content);
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to send External Notifications");
}
if (isTest is false && result)
{
return;
}
using var toast = new ToastNotification(LocalizationHelper.GetString(result ? "ExternalNotificationSendSuccess" : "ExternalNotificationSendFail"));
using var toast = new ToastNotification(
LocalizationHelper.GetString(
result ? "ExternalNotificationSendSuccess" : "ExternalNotificationSendFail"));
toast.Show();
}