-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsToastNotificationService.cs
More file actions
24 lines (21 loc) · 1.04 KB
/
Copy pathWindowsToastNotificationService.cs
File metadata and controls
24 lines (21 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ---------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// ---------------------------------------------------
using System.Diagnostics.CodeAnalysis;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace PowerAutomate.Desktop.Modules.Windows.Notifications.Actions;
// Pure toast adapter; every member forwards to Windows notification APIs.
[ExcludeFromCodeCoverage]
internal sealed class WindowsToastNotificationService : INotificationService
{
public void Show(NotificationRequest notification)
{
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(toastXml.GetXml());
xmlDoc.GetElementsByTagName("text")[0].AppendChild(xmlDoc.CreateTextNode(notification.Text));
var toast = new ToastNotification(xmlDoc) { ExpirationTime = notification.ExpirationTime };
ToastNotificationManager.CreateToastNotifier(notification.AppUserModelId).Show(toast);
}
}