mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
fix: catch error from external notifications
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user