5
5
using System . Windows . Input ;
6
6
using System . Windows . Media . Animation ;
7
7
using System . Windows . Media . Imaging ;
8
- using System . Windows . Media ;
9
8
using Flow . Launcher . Helper ;
10
9
using Flow . Launcher . Infrastructure ;
11
10
using Flow . Launcher . Infrastructure . Image ;
12
- using Windows . UI ;
13
- using Windows . Data ;
14
- using Windows . Data . Xml . Dom ;
15
- using Windows . UI . Notifications ;
16
11
17
12
namespace Flow . Launcher
18
13
{
19
14
public partial class Msg : Window
20
15
{
16
+ Storyboard fadeOutStoryboard = new Storyboard ( ) ;
17
+ private bool closing ;
21
18
22
19
public Msg ( )
23
20
{
24
21
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 ;
25
30
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 ;
26
43
}
27
44
28
- public void Show ( string title , string subTitle , string iconPath )
45
+ void imgClose_MouseUp ( object sender , MouseButtonEventArgs e )
29
46
{
47
+ if ( ! closing )
48
+ {
49
+ closing = true ;
50
+ fadeOutStoryboard . Begin ( ) ;
51
+ }
52
+ }
30
53
54
+ private void fadeOutStoryboard_Completed ( object sender , EventArgs e )
55
+ {
56
+ Close ( ) ;
57
+ }
31
58
59
+ public void Show ( string title , string subTitle , string iconPath )
60
+ {
32
61
tbTitle . Text = title ;
33
62
tbSubTitle . Text = subTitle ;
34
63
if ( string . IsNullOrEmpty ( subTitle ) )
@@ -39,23 +68,20 @@ public void Show(string title, string subTitle, string iconPath)
39
68
{
40
69
imgIco . Source = ImageLoader . Load ( Path . Combine ( Constant . ProgramDirectory , "Images\\ app.png" ) ) ;
41
70
}
42
- else
43
- {
71
+ else {
44
72
imgIco . Source = ImageLoader . Load ( iconPath ) ;
45
73
}
46
74
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 ) ;
75
+ Show ( ) ;
57
76
77
+ Dispatcher . InvokeAsync ( async ( ) =>
78
+ {
79
+ if ( ! closing )
80
+ {
81
+ closing = true ;
82
+ await Dispatcher . InvokeAsync ( fadeOutStoryboard . Begin ) ;
83
+ }
84
+ } ) ;
58
85
}
59
-
60
86
}
61
87
}
0 commit comments