2017-10-18 10:32:51 +02:00
|
|
|
|
using System;
|
2017-10-19 15:53:03 +02:00
|
|
|
|
using Windows.Data.Json;
|
2017-10-18 10:32:51 +02:00
|
|
|
|
using Windows.Data.Xml.Dom;
|
|
|
|
|
using Windows.UI.Notifications;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
|
|
|
|
|
2017-12-01 17:59:38 +01:00
|
|
|
|
namespace ModernKeePass.Common
|
2017-10-18 10:32:51 +02:00
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
public static class ToastNotificationHelper
|
2017-10-18 10:32:51 +02:00
|
|
|
|
{
|
2020-03-26 12:25:22 +01:00
|
|
|
|
public static void ShowMovedToast(IVmEntity entity, string action, string text)
|
2017-10-18 10:32:51 +02:00
|
|
|
|
{
|
|
|
|
|
var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
|
|
|
|
|
var toastElements = notificationXml.GetElementsByTagName("text");
|
2020-03-27 13:27:29 +01:00
|
|
|
|
toastElements[0].AppendChild(notificationXml.CreateTextNode($"{action} {entity.Title}"));
|
2017-10-31 18:49:18 +01:00
|
|
|
|
toastElements[1].AppendChild(notificationXml.CreateTextNode(text));
|
2017-10-18 10:32:51 +02:00
|
|
|
|
var toastNode = notificationXml.SelectSingleNode("/toast");
|
|
|
|
|
|
2018-07-26 10:18:00 +02:00
|
|
|
|
// This is useful only for Windows 10 UWP
|
2017-10-19 15:53:03 +02:00
|
|
|
|
var launch = new JsonObject
|
|
|
|
|
{
|
2018-07-26 10:18:00 +02:00
|
|
|
|
{"entityType", JsonValue.CreateStringValue(entity.GetType().Name)},
|
2017-10-19 15:53:03 +02:00
|
|
|
|
{"entityId", JsonValue.CreateStringValue(entity.Id)}
|
|
|
|
|
};
|
|
|
|
|
((XmlElement)toastNode)?.SetAttribute("launch", launch.Stringify());
|
2017-10-18 10:32:51 +02:00
|
|
|
|
|
|
|
|
|
var toast = new ToastNotification(notificationXml)
|
|
|
|
|
{
|
|
|
|
|
ExpirationTime = DateTime.Now.AddSeconds(5)
|
|
|
|
|
};
|
|
|
|
|
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
|
|
|
|
}
|
2017-11-27 15:26:36 +01:00
|
|
|
|
|
|
|
|
|
public static void ShowGenericToast(string title, string text)
|
|
|
|
|
{
|
|
|
|
|
var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
|
|
|
|
|
var toastElements = notificationXml.GetElementsByTagName("text");
|
|
|
|
|
toastElements[0].AppendChild(notificationXml.CreateTextNode(title));
|
|
|
|
|
toastElements[1].AppendChild(notificationXml.CreateTextNode(text));
|
|
|
|
|
|
|
|
|
|
var toast = new ToastNotification(notificationXml)
|
|
|
|
|
{
|
|
|
|
|
ExpirationTime = DateTime.Now.AddSeconds(5)
|
|
|
|
|
};
|
|
|
|
|
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
|
|
|
|
}
|
2018-03-09 18:06:06 +01:00
|
|
|
|
|
|
|
|
|
public static void ShowErrorToast(Exception exception)
|
|
|
|
|
{
|
|
|
|
|
ShowGenericToast(exception.Source, exception.Message);
|
|
|
|
|
}
|
2017-10-18 10:32:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|