Skip to content

Commit 1317077

Browse files
committed
- Change the popup to windows notification
1 parent 1cf2f1b commit 1317077

File tree

1 file changed

+19
-45
lines changed

1 file changed

+19
-45
lines changed

Flow.Launcher/Msg.xaml.cs

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,30 @@
55
using System.Windows.Input;
66
using System.Windows.Media.Animation;
77
using System.Windows.Media.Imaging;
8+
using System.Windows.Media;
89
using Flow.Launcher.Helper;
910
using Flow.Launcher.Infrastructure;
1011
using Flow.Launcher.Infrastructure.Image;
12+
using Windows.UI;
13+
using Windows.Data;
14+
using Windows.Data.Xml.Dom;
15+
using Windows.UI.Notifications;
1116

1217
namespace Flow.Launcher
1318
{
1419
public partial class Msg : Window
1520
{
16-
Storyboard fadeOutStoryboard = new Storyboard();
17-
private bool closing;
1821

1922
public Msg()
2023
{
2124
InitializeComponent();
22-
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
23-
var dipWorkingArea = WindowsInteropHelper.TransformPixelsToDIP(this,
24-
screen.WorkingArea.Width,
25-
screen.WorkingArea.Height);
26-
Left = dipWorkingArea.X - Width;
27-
Top = dipWorkingArea.Y;
28-
showAnimation.From = dipWorkingArea.Y;
29-
showAnimation.To = dipWorkingArea.Y - Height;
3025

31-
// Create the fade out storyboard
32-
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
33-
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5)))
34-
{
35-
AccelerationRatio = 0.2
36-
};
37-
Storyboard.SetTarget(fadeOutAnimation, this);
38-
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
39-
fadeOutStoryboard.Children.Add(fadeOutAnimation);
40-
41-
imgClose.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\close.png"));
42-
imgClose.MouseUp += imgClose_MouseUp;
4326
}
4427

45-
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
28+
public void Show(string title, string subTitle, string iconPath)
4629
{
47-
if (!closing)
48-
{
49-
closing = true;
50-
fadeOutStoryboard.Begin();
51-
}
52-
}
5330

54-
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
55-
{
56-
Close();
57-
}
5831

59-
public void Show(string title, string subTitle, string iconPath)
60-
{
6132
tbTitle.Text = title;
6233
tbSubTitle.Text = subTitle;
6334
if (string.IsNullOrEmpty(subTitle))
@@ -68,20 +39,23 @@ public void Show(string title, string subTitle, string iconPath)
6839
{
6940
imgIco.Source = ImageLoader.Load(Path.Combine(Constant.ProgramDirectory, "Images\\app.png"));
7041
}
71-
else {
42+
else
43+
{
7244
imgIco.Source = ImageLoader.Load(iconPath);
7345
}
7446

75-
Show();
47+
/* Using Windows Notification System */
48+
var ToastTitle = title;
49+
var ToastsubTitle = subTitle;
50+
var Icon = imgIco.Source;
51+
var xml = $"<?xml version=\"1.0\"?><toast><visual><binding template=\"ToastImageAndText04\"><image id=\"1\" src=\"{Icon}\" alt=\"meziantou\"/><text id=\"1\">{ToastTitle}</text>" +
52+
$"<text id=\"2\">{ToastsubTitle}</text></binding></visual></toast>";
53+
var toastXml = new XmlDocument();
54+
toastXml.LoadXml(xml);
55+
var toast = new ToastNotification(toastXml);
56+
ToastNotificationManager.CreateToastNotifier("Flow Launcher").Show(toast);
7657

77-
Dispatcher.InvokeAsync(async () =>
78-
{
79-
if (!closing)
80-
{
81-
closing = true;
82-
await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin);
83-
}
84-
});
8558
}
59+
8660
}
8761
}

0 commit comments

Comments
 (0)