27
27
using System . Windows . Media ;
28
28
using System . Windows . Interop ;
29
29
using Windows . Win32 ;
30
+ using System . Windows . Shapes ;
30
31
31
32
namespace Flow . Launcher
32
33
{
33
34
public partial class MainWindow
34
35
{
35
36
#region Private Fields
36
37
37
- private readonly Storyboard _progressBarStoryboard = new Storyboard ( ) ;
38
- private bool isProgressBarStoryboardPaused ;
39
38
private Settings _settings ;
40
39
private NotifyIcon _notifyIcon ;
41
40
private ContextMenu contextMenu = new ContextMenu ( ) ;
@@ -63,21 +62,14 @@ public MainWindow(Settings settings, MainViewModel mainVM)
63
62
64
63
DataObject . AddPastingHandler ( QueryTextBox , OnPaste ) ;
65
64
66
- this . Loaded += ( _ , _ ) =>
65
+ Loaded += ( _ , _ ) =>
67
66
{
68
67
var handle = new WindowInteropHelper ( this ) . Handle ;
69
68
var win = HwndSource . FromHwnd ( handle ) ;
70
69
win . AddHook ( WndProc ) ;
71
70
} ;
72
71
}
73
72
74
- DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 500 ) , IsEnabled = false } ;
75
-
76
- public MainWindow ( )
77
- {
78
- InitializeComponent ( ) ;
79
- }
80
-
81
73
private int _initialWidth ;
82
74
private int _initialHeight ;
83
75
@@ -225,39 +217,9 @@ private void OnLoaded(object sender, RoutedEventArgs _)
225
217
_viewModel . LastQuerySelected = true ;
226
218
}
227
219
228
- if ( _viewModel . ProgressBarVisibility == Visibility . Visible &&
229
- isProgressBarStoryboardPaused )
230
- {
231
- _progressBarStoryboard . Begin ( ProgressBar , true ) ;
232
- isProgressBarStoryboardPaused = false ;
233
- }
234
-
235
220
if ( _settings . UseAnimation )
236
221
WindowAnimator ( ) ;
237
222
}
238
- else if ( ! isProgressBarStoryboardPaused )
239
- {
240
- _progressBarStoryboard . Stop ( ProgressBar ) ;
241
- isProgressBarStoryboardPaused = true ;
242
- }
243
- } ) ;
244
- break ;
245
- }
246
- case nameof ( MainViewModel . ProgressBarVisibility ) :
247
- {
248
- Dispatcher . Invoke ( ( ) =>
249
- {
250
- if ( _viewModel . ProgressBarVisibility == Visibility . Hidden && ! isProgressBarStoryboardPaused )
251
- {
252
- _progressBarStoryboard . Stop ( ProgressBar ) ;
253
- isProgressBarStoryboardPaused = true ;
254
- }
255
- else if ( _viewModel . MainWindowVisibilityStatus &&
256
- isProgressBarStoryboardPaused )
257
- {
258
- _progressBarStoryboard . Begin ( ProgressBar , true ) ;
259
- isProgressBarStoryboardPaused = false ;
260
- }
261
223
} ) ;
262
224
break ;
263
225
}
@@ -365,7 +327,6 @@ private void InitializeNotifyIcon()
365
327
Icon = Constant . Version == "1.0.0" ? Properties . Resources . dev : Properties . Resources . app ,
366
328
Visible = ! _settings . HideNotifyIcon
367
329
} ;
368
-
369
330
var openIcon = new FontIcon { Glyph = "\ue71e " } ;
370
331
var open = new MenuItem
371
332
{
@@ -376,7 +337,8 @@ private void InitializeNotifyIcon()
376
337
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc " } ;
377
338
var gamemode = new MenuItem
378
339
{
379
- Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) , Icon = gamemodeIcon
340
+ Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ,
341
+ Icon = gamemodeIcon
380
342
} ;
381
343
var positionresetIcon = new FontIcon { Glyph = "\ue73f " } ;
382
344
var positionreset = new MenuItem
@@ -393,7 +355,8 @@ private void InitializeNotifyIcon()
393
355
var exitIcon = new FontIcon { Glyph = "\ue7e8 " } ;
394
356
var exit = new MenuItem
395
357
{
396
- Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) , Icon = exitIcon
358
+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ,
359
+ Icon = exitIcon
397
360
} ;
398
361
399
362
open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
@@ -460,17 +423,49 @@ private async void PositionReset()
460
423
461
424
private void InitProgressbarAnimation ( )
462
425
{
426
+ var progressBarStoryBoard = new Storyboard ( ) ;
427
+
463
428
var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 100 ,
464
429
new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
465
430
var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 0 ,
466
431
new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
467
432
Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
468
433
Storyboard . SetTargetProperty ( da1 , new PropertyPath ( "(Line.X1)" ) ) ;
469
- _progressBarStoryboard . Children . Add ( da ) ;
470
- _progressBarStoryboard . Children . Add ( da1 ) ;
471
- _progressBarStoryboard . RepeatBehavior = RepeatBehavior . Forever ;
434
+ progressBarStoryBoard . Children . Add ( da ) ;
435
+ progressBarStoryBoard . Children . Add ( da1 ) ;
436
+ progressBarStoryBoard . RepeatBehavior = RepeatBehavior . Forever ;
437
+
438
+ da . Freeze ( ) ;
439
+ da1 . Freeze ( ) ;
440
+
441
+ const string progressBarAnimationName = "ProgressBarAnimation" ;
442
+ var beginStoryboard = new BeginStoryboard
443
+ {
444
+ Name = progressBarAnimationName , Storyboard = progressBarStoryBoard
445
+ } ;
446
+
447
+ var stopStoryboard = new StopStoryboard ( )
448
+ {
449
+ BeginStoryboardName = progressBarAnimationName
450
+ } ;
451
+
452
+ var trigger = new Trigger
453
+ {
454
+ Property = VisibilityProperty , Value = Visibility . Visible
455
+ } ;
456
+ trigger . EnterActions . Add ( beginStoryboard ) ;
457
+ trigger . ExitActions . Add ( stopStoryboard ) ;
458
+
459
+ var progressStyle = new Style ( typeof ( Line ) )
460
+ {
461
+ BasedOn = FindResource ( "PendingLineStyle" ) as Style
462
+ } ;
463
+ progressStyle . RegisterName ( progressBarAnimationName , beginStoryboard ) ;
464
+ progressStyle . Triggers . Add ( trigger ) ;
465
+
466
+ ProgressBar . Style = progressStyle ;
467
+
472
468
_viewModel . ProgressBarVisibility = Visibility . Hidden ;
473
- isProgressBarStoryboardPaused = true ;
474
469
}
475
470
476
471
public void WindowAnimator ( )
0 commit comments