Skip to content

Commit 19d7059

Browse files
committed
Add empty & global query for home page
1 parent 4500f1d commit 19d7059

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,8 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
278278
};
279279
}
280280

281-
public static ICollection<PluginPair> ValidPluginsForHomeQuery(Query query)
281+
public static ICollection<PluginPair> ValidPluginsForHomeQuery()
282282
{
283-
if (query is not null)
284-
return Array.Empty<PluginPair>();
285-
286283
return _homePlugins.ToList();
287284
}
288285

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,23 @@ public static class QueryBuilder
88
{
99
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
1010
{
11+
// home query
12+
if (string.IsNullOrEmpty(text))
13+
{
14+
return new Query()
15+
{
16+
Search = string.Empty,
17+
RawQuery = string.Empty,
18+
SearchTerms = Array.Empty<string>(),
19+
ActionKeyword = string.Empty
20+
};
21+
}
22+
1123
// replace multiple white spaces with one white space
1224
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
1325
if (terms.Length == 0)
14-
{ // nothing was typed
26+
{
27+
// nothing was typed
1528
return null;
1629
}
1730

@@ -21,13 +34,15 @@ public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalP
2134
string[] searchTerms;
2235

2336
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
24-
{ // use non global plugin for query
37+
{
38+
// use non global plugin for query
2539
actionKeyword = possibleActionKeyword;
2640
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..].TrimStart() : string.Empty;
2741
searchTerms = terms[1..];
2842
}
2943
else
30-
{ // non action keyword
44+
{
45+
// non action keyword
3146
actionKeyword = string.Empty;
3247
search = rawQuery.TrimStart();
3348
searchTerms = terms;

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,31 +1220,21 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12201220
_updateSource?.Cancel();
12211221

12221222
var query = await ConstructQueryAsync(QueryText, Settings.CustomShortcuts, Settings.BuiltinShortcuts);
1223-
var homeQuery = query == null;
1224-
ICollection<PluginPair> plugins = Array.Empty<PluginPair>();
12251223

12261224
if (query == null) // shortcut expanded
12271225
{
1228-
if (Settings.ShowHomePage)
1229-
{
1230-
plugins = PluginManager.ValidPluginsForHomeQuery(query);
1231-
}
1232-
1233-
if (plugins.Count == 0)
1234-
{
1235-
// Hide and clear results again because running query may show and add some results
1236-
Results.Visibility = Visibility.Collapsed;
1237-
Results.Clear();
1226+
// Hide and clear results again because running query may show and add some results
1227+
Results.Visibility = Visibility.Collapsed;
1228+
Results.Clear();
12381229

1239-
// Reset plugin icon
1240-
PluginIconPath = null;
1241-
PluginIconSource = null;
1242-
SearchIconVisibility = Visibility.Visible;
1230+
// Reset plugin icon
1231+
PluginIconPath = null;
1232+
PluginIconSource = null;
1233+
SearchIconVisibility = Visibility.Visible;
12431234

1244-
// Hide progress bar again because running query may set this to visible
1245-
ProgressBarVisibility = Visibility.Hidden;
1246-
return;
1247-
}
1235+
// Hide progress bar again because running query may set this to visible
1236+
ProgressBarVisibility = Visibility.Hidden;
1237+
return;
12481238
}
12491239

12501240
_updateSource = new CancellationTokenSource();
@@ -1258,16 +1248,22 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12581248
if (_updateSource.Token.IsCancellationRequested) return;
12591249

12601250
// Update the query's IsReQuery property to true if this is a re-query
1261-
if (!homeQuery) query.IsReQuery = isReQuery;
1251+
query.IsReQuery = isReQuery;
12621252

12631253
// handle the exclusiveness of plugin using action keyword
12641254
RemoveOldQueryResults(query);
12651255

12661256
_lastQuery = query;
12671257

1258+
var homeQuery = query.RawQuery == string.Empty;
1259+
ICollection<PluginPair> plugins = Array.Empty<PluginPair>();
12681260
if (homeQuery)
12691261
{
1270-
// Do not show plugin icon if this is a home query
1262+
if (Settings.ShowHomePage)
1263+
{
1264+
plugins = PluginManager.ValidPluginsForHomeQuery();
1265+
}
1266+
12711267
PluginIconPath = null;
12721268
PluginIconSource = null;
12731269
SearchIconVisibility = Visibility.Visible;
@@ -1317,18 +1313,17 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13171313
Task[] tasks;
13181314
if (homeQuery)
13191315
{
1320-
var homeTasks = plugins.Select(plugin => plugin.Metadata.HomeDisabled switch
1316+
tasks = plugins.Select(plugin => plugin.Metadata.HomeDisabled switch
13211317
{
13221318
false => QueryTaskAsync(plugin, _updateSource.Token),
13231319
true => Task.CompletedTask
1324-
}).ToList();
1320+
}).ToArray();
13251321

1322+
// Query history results for home page firstly so it will be put on top of the results
13261323
if (Settings.ShowHistoryResultsForHomePage)
13271324
{
1328-
homeTasks.Add(QueryHistoryTaskAsync());
1325+
await QueryHistoryTaskAsync();
13291326
}
1330-
1331-
tasks = homeTasks.ToArray();
13321327
}
13331328
else
13341329
{
@@ -1465,7 +1460,7 @@ private async Task<Query> ConstructQueryAsync(string queryText, IEnumerable<Cust
14651460
{
14661461
if (string.IsNullOrWhiteSpace(queryText))
14671462
{
1468-
return null;
1463+
return QueryBuilder.Build(string.Empty, PluginManager.NonGlobalPlugins);
14691464
}
14701465

14711466
var queryBuilder = new StringBuilder(queryText);

0 commit comments

Comments
 (0)