Skip to content

Commit a4dea1f

Browse files
committed
Use Microsoft Package to register toast notification
1 parent b9048f5 commit a4dea1f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8989
</PackageReference>
9090
<PackageReference Include="InputSimulator" Version="1.0.4" />
91+
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
9192
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
9293
<PackageReference Include="NHotkey.Wpf" Version="2.1.0" />
9394
<PackageReference Include="NuGet.CommandLine" Version="5.4.0">

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private async void OnClosing(object sender, CancelEventArgs e)
5959
_viewModel.Save();
6060
e.Cancel = true;
6161
await PluginManager.DisposePluginsAsync();
62+
Notification.Uninstall();
6263
Environment.Exit(0);
6364
}
6465

Flow.Launcher/Notification.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Flow.Launcher.Infrastructure;
2+
using Microsoft.Toolkit.Uwp.Notifications;
23
using System;
34
using System.IO;
45
using Windows.Data.Xml.Dom;
@@ -8,10 +9,17 @@ namespace Flow.Launcher
89
{
910
internal static class Notification
1011
{
12+
internal static bool legacy = Environment.OSVersion.Version.Build < 19041;
13+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
14+
internal static void Uninstall()
15+
{
16+
if (!legacy)
17+
ToastNotificationManagerCompat.Uninstall();
18+
}
19+
1120
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
1221
public static void Show(string title, string subTitle, string iconPath)
1322
{
14-
var legacy = Environment.OSVersion.Version.Build < 19041;
1523
// Handle notification for win7/8/early win10
1624
if (legacy)
1725
{
@@ -24,13 +32,11 @@ public static void Show(string title, string subTitle, string iconPath)
2432
? Path.Combine(Constant.ProgramDirectory, "Images\\app.png")
2533
: iconPath;
2634

27-
var xml = $"<?xml version=\"1.0\"?><toast><visual><binding template=\"ToastImageAndText04\"><image id=\"1\" src=\"{Icon}\" alt=\"meziantou\"/><text id=\"1\">{title}</text>" +
28-
$"<text id=\"2\">{subTitle}</text></binding></visual></toast>";
29-
var toastXml = new XmlDocument();
30-
toastXml.LoadXml(xml);
31-
var toast = new ToastNotification(toastXml);
32-
ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast);
33-
35+
new ToastContentBuilder()
36+
.AddText(title, hintMaxLines: 1)
37+
.AddText(subTitle)
38+
.AddAppLogoOverride(new Uri(Icon))
39+
.Show();
3440
}
3541

3642
private static void LegacyShow(string title, string subTitle, string iconPath)

0 commit comments

Comments
 (0)