Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 49 additions & 38 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
Expand All @@ -22,7 +23,6 @@ namespace Flow.Launcher
{
public partial class MainWindow
{

#region Private Fields

private readonly Storyboard _progressBarStoryboard = new Storyboard();
Expand All @@ -40,6 +40,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
_settings = settings;
InitializeComponent();
}

public MainWindow()
{
InitializeComponent();
Expand All @@ -53,7 +54,6 @@ private void OnClosing(object sender, CancelEventArgs e)

private void OnInitialized(object sender, EventArgs e)
{

}

private void OnLoaded(object sender, RoutedEventArgs _)
Expand All @@ -72,47 +72,57 @@ private void OnLoaded(object sender, RoutedEventArgs _)

_viewModel.PropertyChanged += (o, e) =>
{
if (e.PropertyName == nameof(MainViewModel.MainWindowVisibility))
switch (e.PropertyName)
{
if (_viewModel.MainWindowVisibility == Visibility.Visible)
case nameof(MainViewModel.MainWindowVisibility):
{
Activate();
QueryTextBox.Focus();
UpdatePosition();
_settings.ActivateTimes++;
if (!_viewModel.LastQuerySelected)
if (_viewModel.MainWindowVisibility == Visibility.Visible)
{
QueryTextBox.SelectAll();
_viewModel.LastQuerySelected = true;
Activate();
QueryTextBox.Focus();
UpdatePosition();
_settings.ActivateTimes++;
if (!_viewModel.LastQuerySelected)
{
QueryTextBox.SelectAll();
_viewModel.LastQuerySelected = true;
}

if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
}

if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
if (!isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Resume();
isProgressBarStoryboardPaused = false;
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}

break;
}
else if (!isProgressBarStoryboardPaused)
case nameof(MainViewModel.ProgressBarVisibility):
{
_progressBarStoryboard.Pause();
isProgressBarStoryboardPaused = true;
}
}
else if (e.PropertyName == nameof(MainViewModel.ProgressBarVisibility))
{
Dispatcher.Invoke(() =>
{
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
Dispatcher.Invoke(async () =>
{
_progressBarStoryboard.Pause();
isProgressBarStoryboardPaused = true;
}
else if (_viewModel.MainWindowVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Resume();
isProgressBarStoryboardPaused = false;
}
}, System.Windows.Threading.DispatcherPriority.Render);
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
{
await Task.Delay(50);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the delay?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it stop after hiding, or else user may feel a bit stunt.

_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
else if (_viewModel.MainWindowVisibility == Visibility.Visible &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
}, System.Windows.Threading.DispatcherPriority.Render);

break;
}
}
};
_settings.PropertyChanged += (o, e) =>
Expand Down Expand Up @@ -189,14 +199,15 @@ private void InitializeNotifyIcon()

private void InitProgressbarAnimation()
{
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
_progressBarStoryboard.Children.Add(da);
_progressBarStoryboard.Children.Add(da1);
_progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
ProgressBar.BeginStoryboard(_progressBarStoryboard);

_viewModel.ProgressBarVisibility = Visibility.Hidden;
isProgressBarStoryboardPaused = true;
}
Expand All @@ -210,10 +221,10 @@ private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender != null && e.OriginalSource != null)
{
var r = (ResultListBox)sender;
var d = (DependencyObject)e.OriginalSource;
var r = (ResultListBox) sender;
var d = (DependencyObject) e.OriginalSource;
var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem;
var result = (ResultViewModel)item?.DataContext;
var result = (ResultViewModel) item?.DataContext;
if (result != null)
{
if (e.ChangedButton == MouseButton.Left)
Expand Down