2024-03-10 23:04:39 +01:00
|
|
|
|
using Microsoft.Toolkit.Uwp.Notifications;
|
|
|
|
|
|
using Microsoft.Windows.AppNotifications;
|
2024-02-14 02:07:22 +01:00
|
|
|
|
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);
|
2024-02-14 02:07:22 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-02-14 02:07:22 +01:00
|
|
|
|
#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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-14 02:07:22 +01:00
|
|
|
|
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
|
|
|
|
|
2024-02-14 02:07:22 +01:00
|
|
|
|
AppNotification notification = builder.BuildNotification();
|
2024-03-10 23:04:39 +01:00
|
|
|
|
|
2024-02-14 02:07:22 +01:00
|
|
|
|
AppNotificationManager.Default.Show(notification);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|