Skip to content

Commit 8326ba9

Browse files
committed
- change visibility call structure (like powertoy)
- add some opacity trick for empty query - remove start animation
1 parent c6e2dc8 commit 8326ba9

File tree

3 files changed

+84
-25
lines changed

3 files changed

+84
-25
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@
2828
PreviewKeyDown="OnKeyDown"
2929
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
3030
d:DataContext="{d:DesignInstance vm:MainViewModel}">
31-
<Window.Triggers>
32-
<EventTrigger RoutedEvent="Window.Loaded">
33-
<BeginStoryboard>
34-
<Storyboard>
35-
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:.5">
36-
37-
</DoubleAnimation>
38-
<DoubleAnimation Storyboard.TargetProperty="Top" From="530" To="500" Duration="0:0:.5">
39-
<DoubleAnimation.EasingFunction>
40-
<QuarticEase EasingMode="EaseOut"/>
41-
</DoubleAnimation.EasingFunction>
42-
</DoubleAnimation>
43-
</Storyboard>
44-
</BeginStoryboard>
45-
</EventTrigger>
46-
</Window.Triggers>
4731
<Window.Resources>
4832
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter"/>
4933
<converters:BorderClipConverter x:Key="BorderClipConverter"/>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private void OnDeactivated(object sender, EventArgs e)
262262
{
263263
if (_settings.HideWhenDeactive)
264264
{
265-
Hide();
265+
_viewModel.Hide();
266266
}
267267
}
268268

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,18 @@ private void InitializeKeyCommands()
176176
}
177177
else
178178
{
179-
UpdateLastQUeryMode();
180-
var overlayTask = Task.Delay(50).ContinueWith(_ => {
181-
MainWindowVisibility = Visibility.Collapsed;
182-
});
179+
Hide();
180+
}
181+
});
182+
183+
ClearQueryCommand = new RelayCommand(_ =>
184+
{
185+
if (!string.IsNullOrEmpty(QueryText))
186+
{
187+
ChangeQueryText(string.Empty);
188+
189+
// Push Event to UI SystemQuery has changed
190+
//OnPropertyChanged(nameof(SystemQueryText));
183191
}
184192
});
185193

@@ -217,7 +225,8 @@ private void InitializeKeyCommands()
217225

218226
if (hideWindow)
219227
{
220-
MainWindowVisibility = Visibility.Collapsed;
228+
//MainWindowVisibility = Visibility.Collapsed;
229+
Hide();
221230
}
222231

223232
if (SelectedIsFromQueryResults())
@@ -267,7 +276,8 @@ private void InitializeKeyCommands()
267276
Owner = Application.Current.MainWindow
268277
};
269278

270-
MainWindowVisibility = Visibility.Collapsed;
279+
//MainWindowVisibility = Visibility.Collapsed;
280+
Hide();
271281

272282
PluginManager
273283
.ReloadData()
@@ -372,6 +382,7 @@ private ResultsViewModel SelectedResults
372382
public ICommand LoadHistoryCommand { get; set; }
373383
public ICommand OpenResultCommand { get; set; }
374384
public ICommand ReloadPluginDataCommand { get; set; }
385+
public ICommand ClearQueryCommand { get; private set; }
375386

376387
public string OpenResultCommandModifiers { get; private set; }
377388

@@ -683,20 +694,84 @@ private void SetOpenResultModifiers()
683694
OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
684695
}
685696

686-
internal void ToggleFlowLauncher()
697+
public void ToggleFlowLauncher()
687698
{
688699
if (MainWindowVisibility != Visibility.Visible)
689700
{
690701
MainWindowVisibility = Visibility.Visible;
691702
}
692703
else
693704
{
694-
MainWindowVisibility = Visibility.Collapsed;
705+
if (_settings.LastQueryMode == LastQueryMode.Empty)
706+
{
707+
Application.Current.MainWindow.Opacity = 0; // Trick for no delay
708+
ClearQueryCommand.Execute(null);
709+
Task.Run(() =>
710+
{
711+
Thread.Sleep(100);
712+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
713+
{
714+
MainWindowVisibility = Visibility.Collapsed;
715+
Application.Current.MainWindow.Opacity = 1;
716+
}));
717+
});
718+
}
719+
else
720+
{
721+
722+
MainWindowVisibility = Visibility.Collapsed;
723+
}
724+
}
725+
}
726+
727+
public void Hide()
728+
{
729+
if (MainWindowVisibility != Visibility.Collapsed)
730+
{
731+
ToggleFlowLauncher();
695732
}
696733
}
697734

698735
#endregion
699736

737+
private void OnHotkey()
738+
{
739+
if (!ShouldIgnoreHotkeys())
740+
{
741+
// If launcher window was hidden and the hotkey was pressed, start telemetry event
742+
743+
if (_settings.LastQueryMode == LastQueryMode.Empty)
744+
{
745+
ChangeQueryText(string.Empty);
746+
}
747+
else if (_settings.LastQueryMode == LastQueryMode.Preserved)
748+
{
749+
LastQuerySelected = true;
750+
}
751+
else if (_settings.LastQueryMode == LastQueryMode.Selected)
752+
{
753+
LastQuerySelected = false;
754+
}
755+
else
756+
{
757+
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
758+
}
759+
760+
ToggleFlowLauncher();
761+
}
762+
}
763+
764+
765+
/// <summary>
766+
/// Checks if Flow Launcher should ignore any hotkeys
767+
/// </summary>
768+
private bool ShouldIgnoreHotkeys()
769+
{
770+
return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
771+
}
772+
773+
774+
700775
#region Public Methods
701776

702777
public void Save()

0 commit comments

Comments
 (0)