Files
VDownload/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Notifications/NotificationsService.cs

59 lines
1.5 KiB
C#
Raw Normal View History

2024-03-10 23:04:39 +01:00
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Services.UI.Notifications
{
public interface INotificationsService
{
2024-03-10 23:04:39 +01:00
void Initialize(Action notificationInvoked);
void SendNotification(string title, IEnumerable<string> message);
}
public class NotificationsService : INotificationsService
{
2024-03-10 23:04:39 +01:00
#region CONSTRCUTORS
~NotificationsService()
{
AppNotificationManager.Default.Unregister();
}
#endregion
#region PUBLIC METHODS
2024-03-10 23:04:39 +01:00
public void Initialize(Action notificationInvoked)
{
AppNotificationManager.Default.NotificationInvoked += (obj, args) => notificationInvoked.Invoke();
AppNotificationManager.Default.Register();
}
public void SendNotification(string title, IEnumerable<string> message)
{
AppNotificationBuilder builder = new AppNotificationBuilder();
builder.AddText(title);
foreach (string text in message)
{
builder.AddText(text);
}
2024-03-10 23:04:39 +01:00
AppNotification notification = builder.BuildNotification();
2024-03-10 23:04:39 +01:00
AppNotificationManager.Default.Show(notification);
}
#endregion
}
}