From a4dea1f2fd3c34ed63d6c41a2d700afad40bc956 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Thu, 6 Jan 2022 19:15:50 -0600 Subject: [PATCH] Use Microsoft Package to register toast notification --- Flow.Launcher/Flow.Launcher.csproj | 1 + Flow.Launcher/MainWindow.xaml.cs | 1 + Flow.Launcher/Notification.cs | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index f431504c2..35a6389ca 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -88,6 +88,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index c1d170f9a..57b34bc00 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -59,6 +59,7 @@ namespace Flow.Launcher _viewModel.Save(); e.Cancel = true; await PluginManager.DisposePluginsAsync(); + Notification.Uninstall(); Environment.Exit(0); } diff --git a/Flow.Launcher/Notification.cs b/Flow.Launcher/Notification.cs index d8f9fd45e..3f5565eeb 100644 --- a/Flow.Launcher/Notification.cs +++ b/Flow.Launcher/Notification.cs @@ -1,4 +1,5 @@ using Flow.Launcher.Infrastructure; +using Microsoft.Toolkit.Uwp.Notifications; using System; using System.IO; using Windows.Data.Xml.Dom; @@ -8,10 +9,17 @@ namespace Flow.Launcher { internal static class Notification { + internal static bool legacy = Environment.OSVersion.Version.Build < 19041; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "")] + internal static void Uninstall() + { + if (!legacy) + ToastNotificationManagerCompat.Uninstall(); + } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "")] public static void Show(string title, string subTitle, string iconPath) { - var legacy = Environment.OSVersion.Version.Build < 19041; // Handle notification for win7/8/early win10 if (legacy) { @@ -24,13 +32,11 @@ namespace Flow.Launcher ? Path.Combine(Constant.ProgramDirectory, "Images\\app.png") : iconPath; - var xml = $"\"meziantou\"/{title}" + - $"{subTitle}"; - var toastXml = new XmlDocument(); - toastXml.LoadXml(xml); - var toast = new ToastNotification(toastXml); - ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast); - + new ToastContentBuilder() + .AddText(title, hintMaxLines: 1) + .AddText(subTitle) + .AddAppLogoOverride(new Uri(Icon)) + .Show(); } private static void LegacyShow(string title, string subTitle, string iconPath)