From 1317077dd8ab1102c97d93ad0477c255e4aa112b Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Sun, 17 Oct 2021 10:57:50 +0900 Subject: [PATCH 1/6] - Change the popup to windows notification --- Flow.Launcher/Msg.xaml.cs | 66 ++++++++++++--------------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/Flow.Launcher/Msg.xaml.cs b/Flow.Launcher/Msg.xaml.cs index 6bb2fc2dc..c6b26ccd5 100644 --- a/Flow.Launcher/Msg.xaml.cs +++ b/Flow.Launcher/Msg.xaml.cs @@ -5,59 +5,30 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; +using System.Windows.Media; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Image; +using Windows.UI; +using Windows.Data; +using Windows.Data.Xml.Dom; +using Windows.UI.Notifications; namespace Flow.Launcher { public partial class Msg : Window { - Storyboard fadeOutStoryboard = new Storyboard(); - private bool closing; public Msg() { InitializeComponent(); - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - var dipWorkingArea = WindowsInteropHelper.TransformPixelsToDIP(this, - screen.WorkingArea.Width, - screen.WorkingArea.Height); - Left = dipWorkingArea.X - Width; - Top = dipWorkingArea.Y; - showAnimation.From = dipWorkingArea.Y; - showAnimation.To = dipWorkingArea.Y - Height; - // Create the fade out storyboard - fadeOutStoryboard.Completed += fadeOutStoryboard_Completed; - DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5))) - { - AccelerationRatio = 0.2 - }; - Storyboard.SetTarget(fadeOutAnimation, this); - Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty)); - fadeOutStoryboard.Children.Add(fadeOutAnimation); - - imgClose.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\close.png")); - imgClose.MouseUp += imgClose_MouseUp; - } - - void imgClose_MouseUp(object sender, MouseButtonEventArgs e) - { - if (!closing) - { - closing = true; - fadeOutStoryboard.Begin(); - } - } - - private void fadeOutStoryboard_Completed(object sender, EventArgs e) - { - Close(); } public void Show(string title, string subTitle, string iconPath) { + + tbTitle.Text = title; tbSubTitle.Text = subTitle; if (string.IsNullOrEmpty(subTitle)) @@ -68,20 +39,23 @@ namespace Flow.Launcher { imgIco.Source = ImageLoader.Load(Path.Combine(Constant.ProgramDirectory, "Images\\app.png")); } - else { + else + { imgIco.Source = ImageLoader.Load(iconPath); } - Show(); + /* Using Windows Notification System */ + var ToastTitle = title; + var ToastsubTitle = subTitle; + var Icon = imgIco.Source; + var xml = $"\"meziantou\"/{ToastTitle}" + + $"{ToastsubTitle}"; + var toastXml = new XmlDocument(); + toastXml.LoadXml(xml); + var toast = new ToastNotification(toastXml); + ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast); - Dispatcher.InvokeAsync(async () => - { - if (!closing) - { - closing = true; - await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin); - } - }); } + } } From 886d7aab6ce3765407733a5fc52af95a0b78be34 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 16 Oct 2021 21:50:09 -0500 Subject: [PATCH 2/6] 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"), ""); From 0742d0301c4208301f9268d572191c12e6f21219 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 16 Oct 2021 21:53:03 -0500 Subject: [PATCH 3/6] Revert "- Change the popup to windows notification" This reverts commit 1317077dd8ab1102c97d93ad0477c255e4aa112b. --- Flow.Launcher/Msg.xaml.cs | 66 +++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/Flow.Launcher/Msg.xaml.cs b/Flow.Launcher/Msg.xaml.cs index c6b26ccd5..6bb2fc2dc 100644 --- a/Flow.Launcher/Msg.xaml.cs +++ b/Flow.Launcher/Msg.xaml.cs @@ -5,30 +5,59 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; -using System.Windows.Media; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Image; -using Windows.UI; -using Windows.Data; -using Windows.Data.Xml.Dom; -using Windows.UI.Notifications; namespace Flow.Launcher { public partial class Msg : Window { + Storyboard fadeOutStoryboard = new Storyboard(); + private bool closing; public Msg() { InitializeComponent(); + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dipWorkingArea = WindowsInteropHelper.TransformPixelsToDIP(this, + screen.WorkingArea.Width, + screen.WorkingArea.Height); + Left = dipWorkingArea.X - Width; + Top = dipWorkingArea.Y; + showAnimation.From = dipWorkingArea.Y; + showAnimation.To = dipWorkingArea.Y - Height; + // Create the fade out storyboard + fadeOutStoryboard.Completed += fadeOutStoryboard_Completed; + DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5))) + { + AccelerationRatio = 0.2 + }; + Storyboard.SetTarget(fadeOutAnimation, this); + Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty)); + fadeOutStoryboard.Children.Add(fadeOutAnimation); + + imgClose.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\close.png")); + imgClose.MouseUp += imgClose_MouseUp; + } + + void imgClose_MouseUp(object sender, MouseButtonEventArgs e) + { + if (!closing) + { + closing = true; + fadeOutStoryboard.Begin(); + } + } + + private void fadeOutStoryboard_Completed(object sender, EventArgs e) + { + Close(); } public void Show(string title, string subTitle, string iconPath) { - - tbTitle.Text = title; tbSubTitle.Text = subTitle; if (string.IsNullOrEmpty(subTitle)) @@ -39,23 +68,20 @@ namespace Flow.Launcher { imgIco.Source = ImageLoader.Load(Path.Combine(Constant.ProgramDirectory, "Images\\app.png")); } - else - { + else { imgIco.Source = ImageLoader.Load(iconPath); } - /* Using Windows Notification System */ - var ToastTitle = title; - var ToastsubTitle = subTitle; - var Icon = imgIco.Source; - var xml = $"\"meziantou\"/{ToastTitle}" + - $"{ToastsubTitle}"; - var toastXml = new XmlDocument(); - toastXml.LoadXml(xml); - var toast = new ToastNotification(toastXml); - ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast); + Show(); + Dispatcher.InvokeAsync(async () => + { + if (!closing) + { + closing = true; + await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin); + } + }); } - } } From 6e6db2c67b835e04621852b4eb458981e19cc475 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Mon, 25 Oct 2021 17:52:45 -0500 Subject: [PATCH 4/6] fix iconpath other than default icon --- Flow.Launcher/Notification.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/Notification.cs b/Flow.Launcher/Notification.cs index 8933dc95e..b6aba7727 100644 --- a/Flow.Launcher/Notification.cs +++ b/Flow.Launcher/Notification.cs @@ -19,8 +19,8 @@ namespace Flow.Launcher { /* Using Windows Notification System */ var Icon = !File.Exists(iconPath) - ? ImageLoader.Load(Path.Combine(Constant.ProgramDirectory, "Images\\app.png")) - : ImageLoader.Load(iconPath); + ? Path.Combine(Constant.ProgramDirectory, "Images\\app.png") + : iconPath; var xml = $"\"meziantou\"/{title}" + $"{subTitle}"; From b21d965e0baa54b707f12d248309a4b1bc3e4f98 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Tue, 26 Oct 2021 21:26:08 -0500 Subject: [PATCH 5/6] Handle compatibility with win7/8 --- Flow.Launcher/Notification.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/Notification.cs b/Flow.Launcher/Notification.cs index b6aba7727..6b571b467 100644 --- a/Flow.Launcher/Notification.cs +++ b/Flow.Launcher/Notification.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; using System.Windows.Media; using Windows.Data.Xml.Dom; using Windows.UI.Notifications; @@ -17,18 +18,32 @@ namespace Flow.Launcher [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 legacy = Environment.OSVersion.Version.Major < 10; + // Handle notification for win7/8 + if (legacy) + { + LegacyShow(title, subTitle, iconPath); + return; + } + + // Using Windows Notification System var Icon = !File.Exists(iconPath) ? Path.Combine(Constant.ProgramDirectory, "Images\\app.png") : iconPath; var xml = $"\"meziantou\"/{title}" + - $"{subTitle}"; + $"{subTitle}"; var toastXml = new XmlDocument(); toastXml.LoadXml(xml); var toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast); } + + private static void LegacyShow(string title, string subTitle, string iconPath) + { + var msg = new Msg(); + msg.Show(title, subTitle, iconPath); + } } -} +} \ No newline at end of file From 7a4380d290ab956019530d0833fda2405b834c99 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Tue, 26 Oct 2021 21:26:25 -0500 Subject: [PATCH 6/6] Code Cleanup --- Flow.Launcher/Notification.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Flow.Launcher/Notification.cs b/Flow.Launcher/Notification.cs index 6b571b467..2c82e1451 100644 --- a/Flow.Launcher/Notification.cs +++ b/Flow.Launcher/Notification.cs @@ -1,13 +1,6 @@ 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.Forms; -using System.Windows.Media; using Windows.Data.Xml.Dom; using Windows.UI.Notifications;