mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
fix: #6349 put external notification job in dedicated async task context
This commit is contained in:
@@ -627,7 +627,7 @@ namespace MaaWpfGui.Main
|
||||
.Replace("{Datetime}", DateTime.Now.ToString("U"))
|
||||
.Replace("{Preset}", configurationPreset);
|
||||
|
||||
ExternalNotificationService.SendAsync(allTaskCompleteTitle, allTaskCompleteMessage).Wait();
|
||||
ExternalNotificationService.Send(allTaskCompleteTitle, allTaskCompleteMessage);
|
||||
using (var toast = new ToastNotification(allTaskCompleteTitle))
|
||||
{
|
||||
toast.Show();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
@@ -19,14 +20,9 @@ namespace MaaWpfGui.Services.Notification
|
||||
{
|
||||
public static class ExternalNotificationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Send notification
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the notification</param>
|
||||
/// <param name="content">The content of the notification</param>
|
||||
/// <param name="isTest">Indicate if it is a test or not.</param>
|
||||
/// <returns>Async task</returns>
|
||||
public static async Task SendAsync(string title, string content, bool isTest = false)
|
||||
private static readonly List<Task> _taskContainers = new List<Task>();
|
||||
|
||||
private static async Task SendAsync(string title, string content, bool isTest = false)
|
||||
{
|
||||
var enabledProvider = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationEnabled, "Off");
|
||||
|
||||
@@ -47,5 +43,18 @@ namespace MaaWpfGui.Services.Notification
|
||||
using var toast = new ToastNotification(LocalizationHelper.GetString(result ? "ExternalNotificationSendSuccess" : "ExternalNotificationSendFail"));
|
||||
toast.Show();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send notification
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the notification</param>
|
||||
/// <param name="content">The content of the notification</param>
|
||||
/// <param name="isTest">Indicate if it is a test or not.</param>
|
||||
public static void Send(string title, string content, bool isTest = false)
|
||||
{
|
||||
var task = SendAsync(title, content, isTest);
|
||||
_taskContainers.RemoveAll(x => x.Status != TaskStatus.Running);
|
||||
_taskContainers.Add(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
|
||||
#region External Notifications
|
||||
|
||||
public async Task ExternalNotificationSendTest()
|
||||
public void ExternalNotificationSendTest()
|
||||
{
|
||||
await ExternalNotificationService.SendAsync(
|
||||
ExternalNotificationService.Send(
|
||||
LocalizationHelper.GetString("ExternalNotificationSendTestTitle"),
|
||||
LocalizationHelper.GetString("ExternalNotificationSendTestContent"),
|
||||
true);
|
||||
|
||||
Reference in New Issue
Block a user