diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 8a6a7f3f92..07f02f9793 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -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(); diff --git a/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs b/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs index 776cf6af57..b6befe539c 100644 --- a/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs +++ b/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs @@ -11,6 +11,7 @@ // but WITHOUT ANY WARRANTY // +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 { - /// - /// Send notification - /// - /// The title of the notification - /// The content of the notification - /// Indicate if it is a test or not. - /// Async task - public static async Task SendAsync(string title, string content, bool isTest = false) + private static readonly List _taskContainers = new List(); + + 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(); } + + /// + /// Send notification + /// + /// The title of the notification + /// The content of the notification + /// Indicate if it is a test or not. + 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); + } } } diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 66c024e360..2294e1ef08 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -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);