Skip to content

Commit 933582b

Browse files
committed
Change name to search delay & Support plugin search delay
1 parent 2c949d6 commit 933582b

File tree

9 files changed

+98
-40
lines changed

9 files changed

+98
-40
lines changed

Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
5151
}
5252
metadata.Disabled = settings.Disabled;
5353
metadata.Priority = settings.Priority;
54-
metadata.SearchDelayTime = settings.SearchDelayTime;
54+
metadata.SearchDelay = settings.SearchDelay;
5555
}
5656
else
5757
{
@@ -63,7 +63,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
6363
ActionKeywords = metadata.ActionKeywords,
6464
Disabled = metadata.Disabled,
6565
Priority = metadata.Priority,
66-
SearchDelayTime = metadata.SearchDelayTime,
66+
SearchDelay = metadata.SearchDelay,
6767
};
6868
}
6969
}
@@ -76,7 +76,7 @@ public class Plugin
7676
public string Version { get; set; }
7777
public List<string> ActionKeywords { get; set; } // a reference of the action keywords from plugin manager
7878
public int Priority { get; set; }
79-
public int SearchDelayTime { get; set; }
79+
public int SearchDelay { get; set; }
8080

8181
/// <summary>
8282
/// Used only to save the state of the plugin in settings

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,19 @@ public bool SearchQueryResultsWithDelay
285285
OnPropertyChanged();
286286
}
287287
}
288-
public int SearchInputDelay { get; set; } = 120;
288+
public int SearchDelay { get; set; } = 120;
289+
290+
// TODO: Remove debug codes.
291+
public const int SearchDelayInterval = 30 * 60;
289292

290293
[JsonIgnore]
291-
public List<int> SearchInputDelayRange { get; } = new()
294+
public List<int> SearchDelayRange { get; } = new()
292295
{
293296
30, 60, 90, 120, 150, 180, 210, 240, 270, 300
294297
};
295298

296299
[JsonIgnore]
297-
public List<int> PluginSearchInputDelayRange { get; } = new()
300+
public List<int> PluginSearchDelayRange { get; } = new()
298301
{
299302
0, 30, 60, 90, 120, 150
300303
};

Flow.Launcher.Plugin/PluginMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal set
3434

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

37-
public int SearchDelayTime { get; set; }
37+
public int SearchDelay { get; set; }
3838

3939
public string IcoPath { get; set;}
4040

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,18 @@ private void SetupSearchTextBoxReactiveness(bool showResultsWithDelay)
880880
conversion => (sender, eventArg) => conversion(sender, eventArg),
881881
add => QueryTextBox.TextChanged += add,
882882
remove => QueryTextBox.TextChanged -= remove)
883-
.Throttle(TimeSpan.FromMilliseconds(_settings.SearchInputDelay))
884-
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery((TextBox)@event.Sender)))
883+
.Throttle(TimeSpan.FromMilliseconds(_settings.SearchDelay * 10))
884+
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(0, (TextBox)@event.Sender)))
885+
.Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval))
886+
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(30, (TextBox)@event.Sender)))
887+
.Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval))
888+
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(60, (TextBox)@event.Sender)))
889+
.Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval))
890+
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(90, (TextBox)@event.Sender)))
891+
.Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval))
892+
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(120, (TextBox)@event.Sender)))
893+
.Throttle(TimeSpan.FromMilliseconds(Settings.SearchDelayInterval))
894+
.Do(@event => Dispatcher.Invoke(() => PerformSearchQuery(150, (TextBox)@event.Sender)))
885895
.Subscribe();
886896
}
887897
else
@@ -893,14 +903,19 @@ private void SetupSearchTextBoxReactiveness(bool showResultsWithDelay)
893903
private void QueryTextBox_TextChanged(object sender, TextChangedEventArgs e)
894904
{
895905
var textBox = (TextBox)sender;
896-
PerformSearchQuery(textBox);
906+
PerformSearchQuery(null, textBox);
897907
}
898908

899-
private void PerformSearchQuery(TextBox textBox)
909+
// If delayInputTime is null, we will query plugins with all plugin search delay times
910+
private void PerformSearchQuery(int? searchDelay, TextBox textBox)
900911
{
901-
var text = textBox.Text;
902-
_viewModel.QueryText = text;
903-
_viewModel.Query();
912+
// Only update query text when search delay is null or 0
913+
if (searchDelay.GetValueOrDefault(0) == 0)
914+
{
915+
var text = textBox.Text;
916+
_viewModel.QueryText = text;
917+
}
918+
_viewModel.Query(searchDelay);
904919
}
905920

906921
#endregion

Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
Cursor="Hand"
3939
DockPanel.Dock="Right"
4040
FontWeight="Bold"
41-
ItemsSource="{Binding PluginSearchInputDelayRange}"
42-
SelectedItem="{Binding PluginSearchDelayTime}"
41+
ItemsSource="{Binding PluginSearchDelayRange}"
42+
SelectedItem="{Binding PluginSearchDelay}"
4343
ToolTip="{DynamicResource pluginSearchDelayTooltip}" />
4444
</DockPanel>
4545
</Border>

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public bool PortableMode
139139
}
140140
}
141141

142-
public IEnumerable<int> SearchInputDelayRange => Settings.SearchInputDelayRange;
142+
public IEnumerable<int> SearchDelayRange => Settings.SearchDelayRange;
143143

144144
public List<LastQueryModeData> LastQueryModes { get; } =
145145
DropdownDataGeneric<LastQueryMode>.GetValues<LastQueryModeData>("LastQuery");

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
Sub="{DynamicResource searchDelayTimeToolTip}">
190190
<ComboBox
191191
Width="100"
192-
ItemsSource="{Binding SearchInputDelayRange}"
193-
SelectedItem="{Binding Settings.SearchInputDelay}" />
192+
ItemsSource="{Binding SearchDelayRange}"
193+
SelectedItem="{Binding Settings.SearchDelay}" />
194194
</cc:Card>
195195
</cc:CardGroup>
196196

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ public void ReQuery()
274274
{
275275
if (SelectedIsFromQueryResults())
276276
{
277-
QueryResults(isReQuery: true);
277+
QueryResults(null, isReQuery: true);
278278
}
279279
}
280280

281281
public void ReQuery(bool reselect)
282282
{
283283
BackToQueryResults();
284-
QueryResults(isReQuery: true, reSelect: reselect);
284+
QueryResults(null, isReQuery: true, reSelect: reselect);
285285
}
286286

287287
[RelayCommand]
@@ -630,14 +630,14 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
630630
{
631631
// re-query is done in QueryText's setter method
632632
QueryText = queryText;
633-
Query();
633+
Query(null);
634634
// set to false so the subsequent set true triggers
635635
// PropertyChanged and MoveQueryTextToEnd is called
636636
QueryTextCursorMovedToEnd = false;
637637
}
638638
else if (isReQuery)
639639
{
640-
Query(isReQuery: true);
640+
Query(null, isReQuery: true);
641641
}
642642

643643
QueryTextCursorMovedToEnd = true;
@@ -690,12 +690,12 @@ private ResultsViewModel SelectedResults
690690
// http://stackoverflow.com/posts/25895769/revisions
691691
if (string.IsNullOrEmpty(QueryText))
692692
{
693-
Query();
693+
Query(null);
694694
}
695695
else
696696
{
697697
QueryText = string.Empty;
698-
Query();
698+
Query(null);
699699
}
700700
}
701701

@@ -979,19 +979,27 @@ private bool CanExternalPreviewSelectedResult(out string path)
979979

980980
#region Query
981981

982-
public void Query(bool isReQuery = false)
982+
public void Query(int? searchDelay, bool isReQuery = false)
983983
{
984984
if (SelectedIsFromQueryResults())
985985
{
986-
QueryResults(isReQuery);
986+
QueryResults(searchDelay, isReQuery);
987987
}
988988
else if (ContextMenuSelected())
989989
{
990-
QueryContextMenu();
990+
// Only query history when search delay is null or 0
991+
if (searchDelay.GetValueOrDefault(0) == 0)
992+
{
993+
QueryContextMenu();
994+
}
991995
}
992996
else if (HistorySelected())
993997
{
994-
QueryHistory();
998+
// Only query history when search delay is null or 0
999+
if (searchDelay.GetValueOrDefault(0) == 0)
1000+
{
1001+
QueryHistory();
1002+
}
9951003
}
9961004
}
9971005

@@ -1081,7 +1089,7 @@ private void QueryHistory()
10811089

10821090
private readonly IReadOnlyList<Result> _emptyResult = new List<Result>();
10831091

1084-
private async void QueryResults(bool isReQuery = false, bool reSelect = true)
1092+
private async void QueryResults(int? searchDelay, bool isReQuery = false, bool reSelect = true)
10851093
{
10861094
_updateSource?.Cancel();
10871095

@@ -1157,12 +1165,44 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
11571165

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

1160-
var tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
1168+
Task[] tasks;
1169+
if (searchDelay.HasValue)
11611170
{
1162-
false => QueryTask(plugin, reSelect),
1163-
true => Task.CompletedTask
1164-
}).ToArray();
1171+
var searchDelayValue = searchDelay.Value;
1172+
tasks = plugins.Select(plugin => (plugin.Metadata.Disabled || plugin.Metadata.SearchDelay != searchDelayValue) switch
1173+
{
1174+
false => QueryTask(plugin, reSelect),
1175+
true => Task.CompletedTask
1176+
}).ToArray();
11651177

1178+
// TODO: Remove debug codes.
1179+
System.Diagnostics.Debug.WriteLine($"Querying {searchDelayValue}ms");
1180+
foreach (var plugin in plugins)
1181+
{
1182+
if (!(plugin.Metadata.Disabled || plugin.Metadata.SearchDelay != searchDelayValue))
1183+
{
1184+
System.Diagnostics.Debug.WriteLine($"Querying {plugin.Metadata.Name}");
1185+
}
1186+
}
1187+
}
1188+
else
1189+
{
1190+
tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
1191+
{
1192+
false => QueryTask(plugin, reSelect),
1193+
true => Task.CompletedTask
1194+
}).ToArray();
1195+
1196+
// TODO: Remove debug codes.
1197+
System.Diagnostics.Debug.WriteLine($"Querying null ms");
1198+
foreach (var plugin in plugins)
1199+
{
1200+
if (!plugin.Metadata.Disabled)
1201+
{
1202+
System.Diagnostics.Debug.WriteLine($"Querying {plugin.Metadata.Name}");
1203+
}
1204+
}
1205+
}
11661206

11671207
try
11681208
{

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ public bool IsExpanded
8484
}
8585
}
8686

87-
public IEnumerable<int> PluginSearchInputDelayRange { get; } =
88-
Ioc.Default.GetRequiredService<Settings>().PluginSearchInputDelayRange;
87+
public IEnumerable<int> PluginSearchDelayRange { get; } =
88+
Ioc.Default.GetRequiredService<Settings>().PluginSearchDelayRange;
8989

90-
public int PluginSearchDelayTime
90+
public int PluginSearchDelay
9191
{
92-
get => PluginPair.Metadata.SearchDelayTime;
92+
get => PluginPair.Metadata.SearchDelay;
9393
set
9494
{
95-
PluginPair.Metadata.SearchDelayTime = value;
96-
PluginSettingsObject.SearchDelayTime = value;
95+
PluginPair.Metadata.SearchDelay = value;
96+
PluginSettingsObject.SearchDelay = value;
9797
}
9898
}
9999

0 commit comments

Comments
 (0)