From 886d7aab6ce3765407733a5fc52af95a0b78be34 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 16 Oct 2021 21:50:09 -0500 Subject: [PATCH] Move the show method to a static class Notification Co-authored-by: Dobin Park --- Flow.Launcher/Notification.cs | 34 ++++++++++++++++++++++++ Flow.Launcher/PublicAPIInstance.cs | 3 +-- Flow.Launcher/ViewModel/MainViewModel.cs | 7 +---- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 Flow.Launcher/Notification.cs diff --git a/Flow.Launcher/Notification.cs b/Flow.Launcher/Notification.cs new file mode 100644 index 000000000..8933dc95e --- /dev/null +++ b/Flow.Launcher/Notification.cs @@ -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 = "")] + 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 = $"\"meziantou\"/{title}" + + $"{subTitle}"; + var toastXml = new XmlDocument(); + toastXml.LoadXml(xml); + var toast = new ToastNotification(toastXml); + ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast); + + } + } +} diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index f3403696e..f7c91e96f 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -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); }); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6eee51bd8..6f750ceb4 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -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"), "");