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

Search delay #1677

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
Draft
2 changes: 2 additions & 0 deletions Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public string Language
public string TimeFormat { get; set; } = "hh:mm tt";
public string DateFormat { get; set; } = "MM'/'dd ddd";
public bool FirstLaunch { get; set; } = true;

public int SearchDelay { get; set; } = 50;

public double SettingWindowWidth { get; set; } = 1000;
public double SettingWindowHeight { get; set; } = 700;
Expand Down
57 changes: 57 additions & 0 deletions Flow.Launcher.Plugin/PluginMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,51 @@ namespace Flow.Launcher.Plugin
public class PluginMetadata : BaseModel
{
private string _pluginDirectory;
/// <summary>
/// Unique ID of the plugin
/// </summary>
public string ID { get; set; }
/// <summary>
/// Name of the plugin
/// </summary>
public string Name { get; set; }
/// <summary>
/// Author of the plugin
/// </summary>
public string Author { get; set; }
/// <summary>
/// Plugin Version
/// </summary>
public string Version { get; set; }
/// <summary>
/// Programming Language of the plugin
/// </summary>
public string Language { get; set; }
/// <summary>
/// Description of the plugin
/// </summary>
public string Description { get; set; }
/// <summary>
/// Website of the plugin
/// </summary>
public string Website { get; set; }
/// <summary>
/// Whether the plugin is enabled
/// </summary>
public bool Disabled { get; set; }
/// <summary>
/// Executable file path of the plugin
/// </summary>
public string ExecuteFilePath { get; private set;}

/// <summary>
/// Plugin Specified Search Delay
/// </summary>
public int? SearchDelay { get; set; } = null;

/// <summary>
/// Executable file Name of the plugin
/// </summary>
public string ExecuteFileName { get; set; }

public string PluginDirectory
Expand All @@ -31,17 +66,33 @@ internal set
}
}

/// <summary>
/// Action keyword of the plugin (Obsolete)
/// </summary>
public string ActionKeyword { get; set; }

/// <summary>
/// Action keywords of the plugin
/// </summary>
public List<string> ActionKeywords { get; set; }

/// <summary>
/// Icon path of the plugin
/// </summary>
public string IcoPath { get; set;}

/// <summary>
/// Metadata ToString
/// </summary>
/// <returns>Full Name of Plugin</returns>
public override string ToString()
{
return Name;
}

/// <summary>
/// Plugin Priority
/// </summary>
[JsonIgnore]
public int Priority { get; set; }

Expand All @@ -50,8 +101,14 @@ public override string ToString()
/// </summary>
[JsonIgnore]
public long InitTime { get; set; }
/// <summary>
/// Plugin Average Query Time (Statistics)
/// </summary>
[JsonIgnore]
public long AvgQueryTime { get; set; }
/// <summary>
/// Plugin Query Count (Statistics)
/// </summary>
[JsonIgnore]
public int QueryCount { get; set; }
}
Expand Down
4 changes: 3 additions & 1 deletion Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@
<system:String x:Key="hideOnStartup">Hide Flow Launcher on startup</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="querySearchDelay">Search Delay</system:String>
<system:String x:Key="querySearchDelayToolTip">Sets the speed at which search results appear when typing is stopped. Default is 50ms.</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="ShouldUsePinyin">Search with Pinyin</system:String>
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese.</system:String>
<system:String x:Key="AlwaysPreview">Always Preview</system:String>
<system:String x:Key="AlwaysPreviewToolTip">Always open preview panel when Flow starts. Press F1 to toggle preview. </system:String>
<system:String x:Key="AlwaysPreviewToolTip">Always open preview panel when Flow starts. Press F1 to toggle preview.</system:String>
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>

<!-- Setting Plugin -->
Expand Down
11 changes: 8 additions & 3 deletions Flow.Launcher/Languages/ko.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib">
<?xml version="1.0" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- MainWindow -->
<system:String x:Key="registerHotkeyFailed">단축키 등록 실패: {0}</system:String>
<system:String x:Key="couldnotStartCmd">{0}을 실행할 수 없습니다.</system:String>
Expand Down Expand Up @@ -59,12 +62,14 @@
<system:String x:Key="hideOnStartup">시작 시 Flow Launcher 숨김</system:String>
<system:String x:Key="hideNotifyIcon">트레이 아이콘 숨기기</system:String>
<system:String x:Key="hideNotifyIconToolTip">트레이에서 아이콘을 숨길 경우, 검색창 우클릭으로 설정창을 열 수 있습니다.</system:String>
<system:String x:Key="querySearchDelay">검색 지연 시간</system:String>
<system:String x:Key="querySearchDelayToolTip">타이핑이 멈췄을 때 검색 결과가 표시되는 속도를 지정합니다. 빠를수록 타이핑 도중 결과가 갱신됩니다. 기본값은 50ms입니다.</system:String>
<system:String x:Key="querySearchPrecision">쿼리 검색 정밀도</system:String>
<system:String x:Key="querySearchPrecisionToolTip">검색 결과에 필요한 최소 매치 점수를 변경합니다.</system:String>
<system:String x:Key="ShouldUsePinyin">항상 Pinyin 사용</system:String>
<system:String x:Key="ShouldUsePinyinToolTip">Pinyin을 사용하여 검색할 수 있습니다. Pinyin (병음) 은 로마자 중국어 입력 방식입니다.</system:String>
<system:String x:Key="AlwaysPreview">항상 미리보기</system:String>
<system:String x:Key="AlwaysPreviewToolTip">항상 미리보기 패널이 열린 상태로 Flow를 시작합니다. F1키로 미리보기를 on/off 합니다. </system:String>
<system:String x:Key="AlwaysPreviewToolTip">항상 미리보기 패널이 열린 상태로 Flow를 시작합니다. F1키로 미리보기를 on/off 합니다.</system:String>
<system:String x:Key="shadowEffectNotAllowed">반투명 흐림 효과를 사용하는 경우, 그림자 효과를 쓸 수 없습니다.</system:String>

<!-- Setting Plugin -->
Expand Down
33 changes: 33 additions & 0 deletions Flow.Launcher/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,40 @@
Padding="0"
CornerRadius="5"
Style="{DynamicResource SettingGroupBox}">

<StackPanel Orientation="Vertical">
<Border
Margin="0"
BorderThickness="0"
Style="{DynamicResource SettingGroupBox}">
<ItemsControl Style="{StaticResource SettingGrid}">
<StackPanel Style="{StaticResource TextPanel}">
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Style="{DynamicResource SettingTitleLabel}"
Text="{DynamicResource querySearchDelay}" />
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource querySearchDelayToolTip}" />
</StackPanel>
<ComboBox
Grid.Column="2"
MinWidth="95"
Margin="0,0,18,0"
VerticalAlignment="Center"
DisplayMemberPath="Display"
FontSize="14"
ItemsSource="{Binding SearchDelays}"
SelectedValue="{Binding Settings.SearchDelay}"
SelectedValuePath="Value" />
<TextBlock Style="{StaticResource Glyph}">
&#xe916;
</TextBlock>
</ItemsControl>
</Border>
<Separator
Width="Auto"
BorderThickness="1"
Style="{StaticResource SettingSeparatorStyle}" />
<Border
Margin="0"
BorderThickness="0"
Expand Down
40 changes: 12 additions & 28 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,6 @@ private async void QueryResults()
SearchIconVisibility = Visibility.Visible;
}


if (query.ActionKeyword == Plugin.Query.GlobalPluginWildcardSign)
{
// Wait 45 millisecond for query change in global query
// if query changes, return so that it won't be calculated
await Task.Delay(45, currentCancellationToken);
if (currentCancellationToken.IsCancellationRequested)
return;
}

_ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
{
// start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
Expand All @@ -689,19 +679,16 @@ private async void QueryResults()
}
}, currentCancellationToken, TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default);

// plugins is ICollection, meaning LINQ will get the Count and preallocate Array

var tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
{
false => QueryTask(plugin),
true => Task.CompletedTask
}).ToArray();


try
{
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
await Task.WhenAll(tasks);
await Parallel.ForEachAsync(plugins, currentCancellationToken,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is for a better concurrency so we don't really need to do a context switch

async (pair, token) =>
{
await Task.Delay(pair.Metadata.SearchDelay ?? Settings.SearchDelay, token);
if (pair.Metadata.Disabled)
return;
await QueryTask(pair, token);
taooceros marked this conversation as resolved.
Show resolved Hide resolved
});
}
catch (OperationCanceledException)
{
Expand All @@ -721,15 +708,12 @@ private async void QueryResults()
}

// Local function
async Task QueryTask(PluginPair plugin)
async ValueTask QueryTask(PluginPair plugin, CancellationToken token = default)
{
// Since it is wrapped within a ThreadPool Thread, the synchronous context is null
// Task.Yield will force it to run in ThreadPool
await Task.Yield();

IReadOnlyList<Result> results = await PluginManager.QueryForPluginAsync(plugin, query, currentCancellationToken);
IReadOnlyList<Result> results = await PluginManager.QueryForPluginAsync(plugin, query, token);

currentCancellationToken.ThrowIfCancellationRequested();
if (token.IsCancellationRequested)
return;

results ??= _emptyResult;

Expand Down
27 changes: 27 additions & 0 deletions Flow.Launcher/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ private void UpdateLastQueryModeDisplay()
}
}


public class SearchDelay
{
public string Display { get; set; }
public int Value { get; set; }
}
public List<SearchDelay> SearchDelays
{
get
{
List<SearchDelay> delay = new List<SearchDelay>();
SearchDelay Fast = new SearchDelay();
Fast.Display = "50ms";
Fast.Value = 50;
SearchDelay Normal = new SearchDelay();
Normal.Display = "100ms";
Normal.Value = 100;
SearchDelay Slow = new SearchDelay();
Slow.Display = "150ms";
Slow.Value = 150;
delay.Add(Fast);
delay.Add(Normal);
delay.Add(Slow);
return delay;
}
}

public string Language
{
get
Expand Down