Move the show method to a static class Notification

Co-authored-by: Dobin Park <onesound@oooz.net>
This commit is contained in:
Kevin Zhang 2021-10-16 21:50:09 -05:00
parent 1317077dd8
commit 886d7aab6c
3 changed files with 36 additions and 8 deletions

View file

@ -0,0 +1,34 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Image;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace Flow.Launcher
{
internal static class Notification
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
public static void Show(string title, string subTitle, string iconPath)
{
/* Using Windows Notification System */
var Icon = !File.Exists(iconPath)
? ImageLoader.Load(Path.Combine(Constant.ProgramDirectory, "Images\\app.png"))
: ImageLoader.Load(iconPath);
var xml = $"<?xml version=\"1.0\"?><toast><visual><binding template=\"ToastImageAndText04\"><image id=\"1\" src=\"{Icon}\" alt=\"meziantou\"/><text id=\"1\">{title}</text>" +
$"<text id=\"2\">{subTitle}</text></binding></visual></toast>";
var toastXml = new XmlDocument();
toastXml.LoadXml(xml);
var toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast);
}
}
}

View file

@ -95,8 +95,7 @@ namespace Flow.Launcher
{
Application.Current.Dispatcher.Invoke(() =>
{
var msg = useMainWindowAsOwner ? new Msg {Owner = Application.Current.MainWindow} : new Msg();
msg.Show(title, subTitle, iconPath);
Notification.Show(title, subTitle, iconPath);
});
}

View file

@ -239,11 +239,6 @@ namespace Flow.Launcher.ViewModel
ReloadPluginDataCommand = new RelayCommand(_ =>
{
var msg = new Msg
{
Owner = Application.Current.MainWindow
};
MainWindowVisibility = Visibility.Collapsed;
PluginManager
@ -251,7 +246,7 @@ namespace Flow.Launcher.ViewModel
.ContinueWith(_ =>
Application.Current.Dispatcher.Invoke(() =>
{
msg.Show(
Notification.Show(
InternationalizationManager.Instance.GetTranslation("success"),
InternationalizationManager.Instance.GetTranslation("completedSuccessfully"),
"");