1
1
using System ;
2
2
using System . ComponentModel ;
3
+ using System . Threading . Tasks ;
3
4
using System . Windows ;
4
5
using System . Windows . Input ;
5
6
using System . Windows . Media . Animation ;
@@ -22,7 +23,6 @@ namespace Flow.Launcher
22
23
{
23
24
public partial class MainWindow
24
25
{
25
-
26
26
#region Private Fields
27
27
28
28
private readonly Storyboard _progressBarStoryboard = new Storyboard ( ) ;
@@ -40,6 +40,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
40
40
_settings = settings ;
41
41
InitializeComponent ( ) ;
42
42
}
43
+
43
44
public MainWindow ( )
44
45
{
45
46
InitializeComponent ( ) ;
@@ -53,7 +54,6 @@ private void OnClosing(object sender, CancelEventArgs e)
53
54
54
55
private void OnInitialized ( object sender , EventArgs e )
55
56
{
56
-
57
57
}
58
58
59
59
private void OnLoaded ( object sender , RoutedEventArgs _ )
@@ -72,47 +72,57 @@ private void OnLoaded(object sender, RoutedEventArgs _)
72
72
73
73
_viewModel . PropertyChanged += ( o , e ) =>
74
74
{
75
- if ( e . PropertyName == nameof ( MainViewModel . MainWindowVisibility ) )
75
+ switch ( e . PropertyName )
76
76
{
77
- if ( _viewModel . MainWindowVisibility == Visibility . Visible )
77
+ case nameof ( MainViewModel . MainWindowVisibility ) :
78
78
{
79
- Activate ( ) ;
80
- QueryTextBox . Focus ( ) ;
81
- UpdatePosition ( ) ;
82
- _settings . ActivateTimes ++ ;
83
- if ( ! _viewModel . LastQuerySelected )
79
+ if ( _viewModel . MainWindowVisibility == Visibility . Visible )
84
80
{
85
- QueryTextBox . SelectAll ( ) ;
86
- _viewModel . LastQuerySelected = true ;
81
+ Activate ( ) ;
82
+ QueryTextBox . Focus ( ) ;
83
+ UpdatePosition ( ) ;
84
+ _settings . ActivateTimes ++ ;
85
+ if ( ! _viewModel . LastQuerySelected )
86
+ {
87
+ QueryTextBox . SelectAll ( ) ;
88
+ _viewModel . LastQuerySelected = true ;
89
+ }
90
+
91
+ if ( _viewModel . ProgressBarVisibility == Visibility . Visible && isProgressBarStoryboardPaused )
92
+ {
93
+ _progressBarStoryboard . Begin ( ProgressBar , true ) ;
94
+ isProgressBarStoryboardPaused = false ;
95
+ }
87
96
}
88
97
89
- if ( _viewModel . ProgressBarVisibility == Visibility . Visible && isProgressBarStoryboardPaused )
98
+ if ( ! isProgressBarStoryboardPaused )
90
99
{
91
- _progressBarStoryboard . Resume ( ) ;
92
- isProgressBarStoryboardPaused = false ;
100
+ _progressBarStoryboard . Stop ( ProgressBar ) ;
101
+ isProgressBarStoryboardPaused = true ;
93
102
}
103
+
104
+ break ;
94
105
}
95
- else if ( ! isProgressBarStoryboardPaused )
106
+ case nameof ( MainViewModel . ProgressBarVisibility ) :
96
107
{
97
- _progressBarStoryboard . Pause ( ) ;
98
- isProgressBarStoryboardPaused = true ;
99
- }
100
- }
101
- else if ( e . PropertyName == nameof ( MainViewModel . ProgressBarVisibility ) )
102
- {
103
- Dispatcher . Invoke ( ( ) =>
104
- {
105
- if ( _viewModel . ProgressBarVisibility == Visibility . Hidden && ! isProgressBarStoryboardPaused )
108
+ Dispatcher . Invoke ( async ( ) =>
106
109
{
107
- _progressBarStoryboard . Pause ( ) ;
108
- isProgressBarStoryboardPaused = true ;
109
- }
110
- else if ( _viewModel . MainWindowVisibility == Visibility . Visible && isProgressBarStoryboardPaused )
111
- {
112
- _progressBarStoryboard . Resume ( ) ;
113
- isProgressBarStoryboardPaused = false ;
114
- }
115
- } , System . Windows . Threading . DispatcherPriority . Render ) ;
110
+ if ( _viewModel . ProgressBarVisibility == Visibility . Hidden && ! isProgressBarStoryboardPaused )
111
+ {
112
+ await Task . Delay ( 50 ) ;
113
+ _progressBarStoryboard . Stop ( ProgressBar ) ;
114
+ isProgressBarStoryboardPaused = true ;
115
+ }
116
+ else if ( _viewModel . MainWindowVisibility == Visibility . Visible &&
117
+ isProgressBarStoryboardPaused )
118
+ {
119
+ _progressBarStoryboard . Begin ( ProgressBar , true ) ;
120
+ isProgressBarStoryboardPaused = false ;
121
+ }
122
+ } , System . Windows . Threading . DispatcherPriority . Render ) ;
123
+
124
+ break ;
125
+ }
116
126
}
117
127
} ;
118
128
_settings . PropertyChanged += ( o , e ) =>
@@ -189,14 +199,15 @@ private void InitializeNotifyIcon()
189
199
190
200
private void InitProgressbarAnimation ( )
191
201
{
192
- var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 100 , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
202
+ var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 100 ,
203
+ new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
193
204
var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
194
205
Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
195
206
Storyboard . SetTargetProperty ( da1 , new PropertyPath ( "(Line.X1)" ) ) ;
196
207
_progressBarStoryboard . Children . Add ( da ) ;
197
208
_progressBarStoryboard . Children . Add ( da1 ) ;
198
209
_progressBarStoryboard . RepeatBehavior = RepeatBehavior . Forever ;
199
- ProgressBar . BeginStoryboard ( _progressBarStoryboard ) ;
210
+
200
211
_viewModel . ProgressBarVisibility = Visibility . Hidden ;
201
212
isProgressBarStoryboardPaused = true ;
202
213
}
@@ -210,10 +221,10 @@ private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
210
221
{
211
222
if ( sender != null && e . OriginalSource != null )
212
223
{
213
- var r = ( ResultListBox ) sender ;
214
- var d = ( DependencyObject ) e . OriginalSource ;
224
+ var r = ( ResultListBox ) sender ;
225
+ var d = ( DependencyObject ) e . OriginalSource ;
215
226
var item = ItemsControl . ContainerFromElement ( r , d ) as ListBoxItem ;
216
- var result = ( ResultViewModel ) item ? . DataContext ;
227
+ var result = ( ResultViewModel ) item ? . DataContext ;
217
228
if ( result != null )
218
229
{
219
230
if ( e . ChangedButton == MouseButton . Left )
0 commit comments