Skip to content

Commit 76f8121

Browse files
authored
Merge pull request #758 from onesounds/PopupRedesign
Change the popup to windows notification
2 parents 8cb7cbb + 7a4380d commit 76f8121

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

Flow.Launcher/Notification.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Flow.Launcher.Infrastructure;
2+
using System;
3+
using System.IO;
4+
using Windows.Data.Xml.Dom;
5+
using Windows.UI.Notifications;
6+
7+
namespace Flow.Launcher
8+
{
9+
internal static class Notification
10+
{
11+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
12+
public static void Show(string title, string subTitle, string iconPath)
13+
{
14+
var legacy = Environment.OSVersion.Version.Major < 10;
15+
// Handle notification for win7/8
16+
if (legacy)
17+
{
18+
LegacyShow(title, subTitle, iconPath);
19+
return;
20+
}
21+
22+
// Using Windows Notification System
23+
var Icon = !File.Exists(iconPath)
24+
? Path.Combine(Constant.ProgramDirectory, "Images\\app.png")
25+
: iconPath;
26+
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+
34+
}
35+
36+
private static void LegacyShow(string title, string subTitle, string iconPath)
37+
{
38+
var msg = new Msg();
39+
msg.Show(title, subTitle, iconPath);
40+
}
41+
}
42+
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public void ShowMsg(string title, string subTitle, string iconPath, bool useMain
9090
{
9191
Application.Current.Dispatcher.Invoke(() =>
9292
{
93-
var msg = useMainWindowAsOwner ? new Msg {Owner = Application.Current.MainWindow} : new Msg();
94-
msg.Show(title, subTitle, iconPath);
93+
Notification.Show(title, subTitle, iconPath);
9594
});
9695
}
9796

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,14 @@ private void InitializeKeyCommands()
272272

273273
ReloadPluginDataCommand = new RelayCommand(_ =>
274274
{
275-
var msg = new Msg
276-
{
277-
Owner = Application.Current.MainWindow
278-
};
279-
280275
Hide();
281-
276+
282277
PluginManager
283278
.ReloadData()
284279
.ContinueWith(_ =>
285280
Application.Current.Dispatcher.Invoke(() =>
286281
{
287-
msg.Show(
282+
Notification.Show(
288283
InternationalizationManager.Instance.GetTranslation("success"),
289284
InternationalizationManager.Instance.GetTranslation("completedSuccessfully"),
290285
"");

0 commit comments

Comments
 (0)