Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Smooth & Search delay #3350

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
}
metadata.Disabled = settings.Disabled;
metadata.Priority = settings.Priority;
metadata.SearchDelay = settings.SearchDelay;
}
else
{
Expand All @@ -59,9 +60,10 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
ID = metadata.ID,
Name = metadata.Name,
Version = metadata.Version,
ActionKeywords = metadata.ActionKeywords,
ActionKeywords = metadata.ActionKeywords,
Disabled = metadata.Disabled,
Priority = metadata.Priority
Priority = metadata.Priority,
SearchDelay = metadata.SearchDelay,
};
}
}
Expand All @@ -74,6 +76,7 @@ public class Plugin
public string Version { get; set; }
public List<string> ActionKeywords { get; set; } // a reference of the action keywords from plugin manager
public int Priority { get; set; }
public int SearchDelay { get; set; }

/// <summary>
/// Used only to save the state of the plugin in settings
Expand Down
24 changes: 24 additions & 0 deletions Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,30 @@ public bool HideNotifyIcon
public bool LeaveCmdOpen { get; set; }
public bool HideWhenDeactivated { get; set; } = true;

bool _searchQueryResultsWithDelay { get; set; }
public bool SearchQueryResultsWithDelay
{
get => _searchQueryResultsWithDelay;
set
{
_searchQueryResultsWithDelay = value;
OnPropertyChanged();
}
}
public int SearchDelay { get; set; } = 120;

[JsonIgnore]
public List<int> SearchDelayRange { get; } = new()
{
30, 60, 90, 120, 150, 180, 210, 240, 270, 300
};

[JsonIgnore]
public List<int> PluginSearchDelayRange { get; } = new()
{
0, 30, 60, 90, 120, 150
};

[JsonConverter(typeof(JsonStringEnumConverter))]
public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.Cursor;

Expand Down
4 changes: 3 additions & 1 deletion Flow.Launcher.Plugin/PluginMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ internal set
public string ActionKeyword { get; set; }

public List<string> ActionKeywords { get; set; }

public bool HideActionKeywordPanel { get; set; }

public int SearchDelay { get; set; }

public string IcoPath { get; set;}

Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/Flow.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
<PackageReference Include="SemanticVersioning" Version="3.0.0" />
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
<PackageReference Include="TaskScheduler" Version="2.12.1" />
<PackageReference Include="VirtualizingWrapPanel" Version="2.1.1" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
<system:String x:Key="hideOnStartupToolTip">Flow Launcher search window is hidden in the tray after starting up.</system:String>
<system:String x:Key="hideNotifyIcon">Hide tray icon</system:String>
<system:String x:Key="hideNotifyIconToolTip">When the icon is hidden from the tray, the Settings menu can be opened by right-clicking on the search window.</system:String>
<system:String x:Key="searchDelay">Search Delay</system:String>
<system:String x:Key="searchDelayToolTip">Delay for a while to search when typing. This reduces interface jumpiness and result load.</system:String>
<system:String x:Key="searchDelayTime">Search Delay Time</system:String>
<system:String x:Key="searchDelayTimeToolTip">Delay time after which search results appear when typing is stopped. Default is 120ms.</system:String>
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
<system:String x:Key="querySearchPrecisionToolTip">Changes minimum match score required for results.</system:String>
<system:String x:Key="SearchPrecisionNone">None</system:String>
Expand Down Expand Up @@ -125,6 +129,7 @@
<system:String x:Key="currentActionKeywords">Current action keyword</system:String>
<system:String x:Key="newActionKeyword">New action keyword</system:String>
<system:String x:Key="actionKeywordsTooltip">Change Action Keywords</system:String>
<system:String x:Key="pluginSearchDelayTooltip">Change Seach Delay Time</system:String>
<system:String x:Key="currentPriority">Current Priority</system:String>
<system:String x:Key="newPriority">New Priority</system:String>
<system:String x:Key="priority">Priority</system:String>
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
PreviewDragOver="QueryTextBox_OnPreviewDragOver"
PreviewKeyUp="QueryTextBox_KeyUp"
Style="{DynamicResource QueryBoxStyle}"
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding QueryText, Mode=OneWay}"
Visibility="Visible"
WindowChrome.IsHitTestVisibleInChrome="True">
<TextBox.CommandBindings>
Expand Down
68 changes: 63 additions & 5 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Linq;
using System.Media;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -21,6 +22,8 @@
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.ViewModel;
using ModernWpf.Controls;
using DataObject = System.Windows.DataObject;
using Key = System.Windows.Input.Key;
using MouseButtons = System.Windows.Forms.MouseButtons;
using NotifyIcon = System.Windows.Forms.NotifyIcon;
using Screen = System.Windows.Forms.Screen;
Expand Down Expand Up @@ -56,7 +59,10 @@ public partial class MainWindow
// Window Animation
private const double DefaultRightMargin = 66; //* this value from base.xaml
private bool _animating;
private bool _isClockPanelAnimating = false; // 애니메이션 실행 중인지 여부
private bool _isClockPanelAnimating = false;

// Search Delay
private IDisposable _reactiveSubscription;

#endregion

Expand Down Expand Up @@ -93,6 +99,9 @@ private void OnSourceInitialized(object sender, EventArgs e)

private async void OnLoaded(object sender, RoutedEventArgs _)
{
// Setup search text box reactiveness
SetupSearchTextBoxReactiveness(_settings.SearchQueryResultsWithDelay);

// Check first launch
if (_settings.FirstLaunch)
{
Expand Down Expand Up @@ -137,10 +146,11 @@ private async void OnLoaded(object sender, RoutedEventArgs _)

// Reset preview
_viewModel.ResetPreview();

// Since the default main window visibility is visible, so we need set focus during startup
QueryTextBox.Focus();

// View model property changed event
_viewModel.PropertyChanged += (o, e) =>
{
switch (e.PropertyName)
Expand All @@ -155,7 +165,7 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
{
SoundPlay();
}

UpdatePosition(false);
_viewModel.ResetPreview();
Activate();
Expand Down Expand Up @@ -191,6 +201,7 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
}
};

// Settings property changed event
_settings.PropertyChanged += (o, e) =>
{
switch (e.PropertyName)
Expand All @@ -210,6 +221,9 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
case nameof(Settings.WindowTop):
Top = _settings.WindowTop;
break;
case nameof(Settings.SearchQueryResultsWithDelay):
SetupSearchTextBoxReactiveness(_settings.SearchQueryResultsWithDelay);
break;
}
};

Expand Down Expand Up @@ -911,7 +925,6 @@ private void UpdateClockPanelVisibility()
}
}


private static double GetOpacityFromStyle(Style style, double defaultOpacity = 1.0)
{
if (style == null)
Expand Down Expand Up @@ -983,11 +996,56 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e)
be.UpdateSource();
}
}

private void QueryTextBox_OnPreviewDragOver(object sender, DragEventArgs e)
{
e.Handled = true;
}

#endregion

#region Search Delay

// Edited from: https://github.com/microsoft/PowerToys

private void SetupSearchTextBoxReactiveness(bool showResultsWithDelay)
{
if (_reactiveSubscription != null)
{
_reactiveSubscription.Dispose();
_reactiveSubscription = null;
}

QueryTextBox.TextChanged -= QueryTextBox_TextChanged;

if (showResultsWithDelay)
{
_reactiveSubscription = Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
conversion => (sender, eventArg) => conversion(sender, eventArg),
add => QueryTextBox.TextChanged += add,
remove => QueryTextBox.TextChanged -= remove)
.Throttle(TimeSpan.FromMilliseconds(_settings.SearchDelay * 10))
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(true, (TextBox)@event.Sender)))
.Subscribe();
}
else
{
QueryTextBox.TextChanged += QueryTextBox_TextChanged;
}
}

private void QueryTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var textBox = (TextBox)sender;
PerformSearchQuery(false, textBox);
}

private void PerformSearchQuery(bool searchDelay, TextBox textBox)
{
var text = textBox.Text;
_viewModel.QueryText = text;
_viewModel.Query(searchDelay);
}

#endregion
}
Expand Down
45 changes: 25 additions & 20 deletions Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<UserControl x:Class="Flow.Launcher.Resources.Controls.InstalledPluginDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl
x:Class="Flow.Launcher.Resources.Controls.InstalledPluginDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<Expander
Padding="0"
BorderThickness="0"
Expand All @@ -28,7 +30,7 @@
Grid.Column="0"
Width="32"
Height="32"
Source="{Binding Image, IsAsync=True}" />
Source="{Binding Image, Mode=OneWay, IsAsync=True}" />
<StackPanel Grid.Column="1" Margin="16 0 14 0">
<TextBlock
Foreground="{DynamicResource Color05B}"
Expand All @@ -37,12 +39,15 @@
ToolTip="{Binding PluginPair.Metadata.Version}" />
<TextBlock
Margin="0 2 0 0"
Foreground="{DynamicResource Color04B}"
FontSize="12"
Foreground="{DynamicResource Color04B}"
Text="{Binding PluginPair.Metadata.Description}"
TextWrapping="WrapWithOverflow" />
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
<StackPanel
Grid.Column="2"
HorizontalAlignment="Right"
Orientation="Horizontal">
<TextBlock
Margin="0 0 8 0"
VerticalAlignment="Center"
Expand Down Expand Up @@ -70,9 +75,7 @@
<Setter Property="FontWeight" Value="DemiBold" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}"
Value="0">
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
<Setter Property="Foreground" Value="{DynamicResource Color08B}" />
<Setter Property="FontWeight" Value="Normal" />
</DataTrigger>
Expand All @@ -95,10 +98,12 @@
<StackPanel>
<ContentControl Content="{Binding BottomPart1}" />

<ContentControl Content="{Binding BottomPart2}" />

<Border
BorderThickness="0 1 0 0"
Background="{DynamicResource Color00B}"
BorderBrush="{DynamicResource Color03B}"
Background="{DynamicResource Color00B}">
BorderThickness="0 1 0 0">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
Expand All @@ -115,7 +120,7 @@
Content="{Binding SettingControl}" />
</Border>

<ContentControl Content="{Binding BottomPart2}" />
<ContentControl Content="{Binding BottomPart3}" />
</StackPanel>
</Expander>
</UserControl>
46 changes: 46 additions & 0 deletions Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<UserControl
x:Class="Flow.Launcher.Resources.Controls.InstalledPluginSearchDelay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<Border
Width="Auto"
Height="52"
Margin="0"
Padding="0"
BorderThickness="0 1 0 0"
CornerRadius="0"
Style="{DynamicResource SettingGroupBox}">
<DockPanel Margin="22 0 18 0" VerticalAlignment="Center">
<TextBlock
Margin="48 0 10 0"
DockPanel.Dock="Left"
Style="{StaticResource Glyph}">
&#xE916;
</TextBlock>
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
DockPanel.Dock="Left"
Style="{DynamicResource SettingTitleLabel}"
Text="{DynamicResource searchDelayTime}" />
<ComboBox
Width="100"
Height="34"
Margin="5 0 0 0"
HorizontalAlignment="Right"
Cursor="Hand"
DockPanel.Dock="Right"
FontWeight="Bold"
ItemsSource="{Binding PluginSearchDelayRange}"
SelectedItem="{Binding PluginSearchDelay}"
ToolTip="{DynamicResource pluginSearchDelayTooltip}" />
</DockPanel>
</Border>
</UserControl>
Loading
Loading