mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-19 15:20:15 -05:00
34 lines
730 B
C#
34 lines
730 B
C#
namespace ColorControl.UI.Services;
|
|
|
|
public class NotificationService
|
|
{
|
|
public event Func<NotificationDto, Task>? OnNotification;
|
|
|
|
private List<NotificationDto> _scheduledNotifications = new();
|
|
|
|
public void SendNotification(NotificationDto notification)
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
if (notification.ScheduledAt == null || notification.ScheduledAt <= now)
|
|
{
|
|
OnNotification?.Invoke(notification);
|
|
|
|
return;
|
|
}
|
|
|
|
Task.Run(async () =>
|
|
{
|
|
await Task.Delay(notification.ScheduledAt.Value - now);
|
|
|
|
OnNotification?.Invoke(notification);
|
|
});
|
|
}
|
|
|
|
public async Task SendNotificationDirect(NotificationDto notification)
|
|
{
|
|
if (OnNotification != null)
|
|
{
|
|
await OnNotification.Invoke(notification);
|
|
}
|
|
}
|
|
} |