2727using System . Windows . Media ;
2828using System . Windows . Interop ;
2929using Windows . Win32 ;
30+ using System . Windows . Shapes ;
3031
3132namespace Flow . Launcher
3233{
3334 public partial class MainWindow
3435 {
3536 #region Private Fields
3637
37- private readonly Storyboard _progressBarStoryboard = new Storyboard ( ) ;
38- private bool isProgressBarStoryboardPaused ;
3938 private Settings _settings ;
4039 private NotifyIcon _notifyIcon ;
4140 private ContextMenu contextMenu = new ContextMenu ( ) ;
@@ -63,21 +62,14 @@ public MainWindow(Settings settings, MainViewModel mainVM)
6362
6463 DataObject . AddPastingHandler ( QueryTextBox , OnPaste ) ;
6564
66- this . Loaded += ( _ , _ ) =>
65+ Loaded += ( _ , _ ) =>
6766 {
6867 var handle = new WindowInteropHelper ( this ) . Handle ;
6968 var win = HwndSource . FromHwnd ( handle ) ;
7069 win . AddHook ( WndProc ) ;
7170 } ;
7271 }
7372
74- DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 500 ) , IsEnabled = false } ;
75-
76- public MainWindow ( )
77- {
78- InitializeComponent ( ) ;
79- }
80-
8173 private int _initialWidth ;
8274 private int _initialHeight ;
8375
@@ -225,39 +217,9 @@ private void OnLoaded(object sender, RoutedEventArgs _)
225217 _viewModel . LastQuerySelected = true ;
226218 }
227219
228- if ( _viewModel . ProgressBarVisibility == Visibility . Visible &&
229- isProgressBarStoryboardPaused )
230- {
231- _progressBarStoryboard . Begin ( ProgressBar , true ) ;
232- isProgressBarStoryboardPaused = false ;
233- }
234-
235220 if ( _settings . UseAnimation )
236221 WindowAnimator ( ) ;
237222 }
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- }
261223 } ) ;
262224 break ;
263225 }
@@ -365,7 +327,6 @@ private void InitializeNotifyIcon()
365327 Icon = Constant . Version == "1.0.0" ? Properties . Resources . dev : Properties . Resources . app ,
366328 Visible = ! _settings . HideNotifyIcon
367329 } ;
368-
369330 var openIcon = new FontIcon { Glyph = "\ue71e " } ;
370331 var open = new MenuItem
371332 {
@@ -376,7 +337,8 @@ private void InitializeNotifyIcon()
376337 var gamemodeIcon = new FontIcon { Glyph = "\ue7fc " } ;
377338 var gamemode = new MenuItem
378339 {
379- Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) , Icon = gamemodeIcon
340+ Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ,
341+ Icon = gamemodeIcon
380342 } ;
381343 var positionresetIcon = new FontIcon { Glyph = "\ue73f " } ;
382344 var positionreset = new MenuItem
@@ -393,7 +355,8 @@ private void InitializeNotifyIcon()
393355 var exitIcon = new FontIcon { Glyph = "\ue7e8 " } ;
394356 var exit = new MenuItem
395357 {
396- Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) , Icon = exitIcon
358+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ,
359+ Icon = exitIcon
397360 } ;
398361
399362 open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
@@ -460,17 +423,49 @@ private async void PositionReset()
460423
461424 private void InitProgressbarAnimation ( )
462425 {
426+ var progressBarStoryBoard = new Storyboard ( ) ;
427+
463428 var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 100 ,
464429 new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
465430 var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 0 ,
466431 new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
467432 Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
468433 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+
472468 _viewModel . ProgressBarVisibility = Visibility . Hidden ;
473- isProgressBarStoryboardPaused = true ;
474469 }
475470
476471 public void WindowAnimator ( )
0 commit comments