Skip to content

Commit

Permalink
"Clear the previous query on launch" has a flicker (#10291)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp committed Mar 18, 2021
1 parent 5e9a31e commit 3a15276
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/modules/launcher/PowerLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Closing="OnClosing"
Background="Transparent"
LocationChanged="OnLocationChanged"
Activated="OnActivated"
Deactivated="OnDeactivated"
IsVisibleChanged="OnVisibilityChanged"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Expand Down
10 changes: 1 addition & 9 deletions src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,12 @@ private void InitializePosition()
_settings.WindowLeft = Left;
}

private void OnActivated(object sender, EventArgs e)
{
if (_settings.ClearInputOnLaunch)
{
_viewModel.ClearQueryCommand.Execute(null);
}
}

private void OnDeactivated(object sender, EventArgs e)
{
if (_settings.HideWhenDeactivated)
{
// (this.FindResource("OutroStoryboard") as Storyboard).Begin();
Hide();
_viewModel.Hide();
}
}

Expand Down
32 changes: 28 additions & 4 deletions src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using interop;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
Expand Down Expand Up @@ -154,7 +155,7 @@ private void OpenResultsEvent(object index, bool isMouseClick)
// SelectedItem returns null if selection is empty.
if (result != null && result.Action != null)
{
MainWindowVisibility = Visibility.Collapsed;
Hide();

Application.Current.Dispatcher.Invoke(() =>
{
Expand Down Expand Up @@ -193,7 +194,7 @@ private void InitializeKeyCommands()
}
else
{
MainWindowVisibility = Visibility.Collapsed;
Hide();
}
});

Expand Down Expand Up @@ -805,15 +806,38 @@ private void OnHotkey()
});
}

private void ToggleWox()
public void ToggleWox()
{
if (MainWindowVisibility != Visibility.Visible)
{
MainWindowVisibility = Visibility.Visible;
}
else
{
MainWindowVisibility = Visibility.Collapsed;
if (_settings.ClearInputOnLaunch && Results.Visibility == Visibility.Visible)
{
ClearQueryCommand.Execute(null);
Task.Run(() =>
{
Thread.Sleep(100);
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
MainWindowVisibility = Visibility.Collapsed;
}));
});
}
else
{
MainWindowVisibility = Visibility.Collapsed;
}
}
}

public void Hide()
{
if (MainWindowVisibility != Visibility.Collapsed)
{
ToggleWox();
}
}

Expand Down

0 comments on commit 3a15276

Please sign in to comment.