mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add empty & global query for home page
This commit is contained in:
parent
4500f1deeb
commit
19d70592a8
3 changed files with 42 additions and 35 deletions
|
|
@ -278,11 +278,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
};
|
||||
}
|
||||
|
||||
public static ICollection<PluginPair> ValidPluginsForHomeQuery(Query query)
|
||||
public static ICollection<PluginPair> ValidPluginsForHomeQuery()
|
||||
{
|
||||
if (query is not null)
|
||||
return Array.Empty<PluginPair>();
|
||||
|
||||
return _homePlugins.ToList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,23 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
|
||||
{
|
||||
// home query
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return new Query()
|
||||
{
|
||||
Search = string.Empty,
|
||||
RawQuery = string.Empty,
|
||||
SearchTerms = Array.Empty<string>(),
|
||||
ActionKeyword = string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
// replace multiple white spaces with one white space
|
||||
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (terms.Length == 0)
|
||||
{ // nothing was typed
|
||||
{
|
||||
// nothing was typed
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -21,13 +34,15 @@ namespace Flow.Launcher.Core.Plugin
|
|||
string[] searchTerms;
|
||||
|
||||
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
|
||||
{ // use non global plugin for query
|
||||
{
|
||||
// use non global plugin for query
|
||||
actionKeyword = possibleActionKeyword;
|
||||
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..].TrimStart() : string.Empty;
|
||||
searchTerms = terms[1..];
|
||||
}
|
||||
else
|
||||
{ // non action keyword
|
||||
{
|
||||
// non action keyword
|
||||
actionKeyword = string.Empty;
|
||||
search = rawQuery.TrimStart();
|
||||
searchTerms = terms;
|
||||
|
|
|
|||
|
|
@ -1220,31 +1220,21 @@ namespace Flow.Launcher.ViewModel
|
|||
_updateSource?.Cancel();
|
||||
|
||||
var query = await ConstructQueryAsync(QueryText, Settings.CustomShortcuts, Settings.BuiltinShortcuts);
|
||||
var homeQuery = query == null;
|
||||
ICollection<PluginPair> plugins = Array.Empty<PluginPair>();
|
||||
|
||||
if (query == null) // shortcut expanded
|
||||
{
|
||||
if (Settings.ShowHomePage)
|
||||
{
|
||||
plugins = PluginManager.ValidPluginsForHomeQuery(query);
|
||||
}
|
||||
|
||||
if (plugins.Count == 0)
|
||||
{
|
||||
// Hide and clear results again because running query may show and add some results
|
||||
Results.Visibility = Visibility.Collapsed;
|
||||
Results.Clear();
|
||||
// Hide and clear results again because running query may show and add some results
|
||||
Results.Visibility = Visibility.Collapsed;
|
||||
Results.Clear();
|
||||
|
||||
// Reset plugin icon
|
||||
PluginIconPath = null;
|
||||
PluginIconSource = null;
|
||||
SearchIconVisibility = Visibility.Visible;
|
||||
// Reset plugin icon
|
||||
PluginIconPath = null;
|
||||
PluginIconSource = null;
|
||||
SearchIconVisibility = Visibility.Visible;
|
||||
|
||||
// Hide progress bar again because running query may set this to visible
|
||||
ProgressBarVisibility = Visibility.Hidden;
|
||||
return;
|
||||
}
|
||||
// Hide progress bar again because running query may set this to visible
|
||||
ProgressBarVisibility = Visibility.Hidden;
|
||||
return;
|
||||
}
|
||||
|
||||
_updateSource = new CancellationTokenSource();
|
||||
|
|
@ -1258,16 +1248,22 @@ namespace Flow.Launcher.ViewModel
|
|||
if (_updateSource.Token.IsCancellationRequested) return;
|
||||
|
||||
// Update the query's IsReQuery property to true if this is a re-query
|
||||
if (!homeQuery) query.IsReQuery = isReQuery;
|
||||
query.IsReQuery = isReQuery;
|
||||
|
||||
// handle the exclusiveness of plugin using action keyword
|
||||
RemoveOldQueryResults(query);
|
||||
|
||||
_lastQuery = query;
|
||||
|
||||
var homeQuery = query.RawQuery == string.Empty;
|
||||
ICollection<PluginPair> plugins = Array.Empty<PluginPair>();
|
||||
if (homeQuery)
|
||||
{
|
||||
// Do not show plugin icon if this is a home query
|
||||
if (Settings.ShowHomePage)
|
||||
{
|
||||
plugins = PluginManager.ValidPluginsForHomeQuery();
|
||||
}
|
||||
|
||||
PluginIconPath = null;
|
||||
PluginIconSource = null;
|
||||
SearchIconVisibility = Visibility.Visible;
|
||||
|
|
@ -1317,18 +1313,17 @@ namespace Flow.Launcher.ViewModel
|
|||
Task[] tasks;
|
||||
if (homeQuery)
|
||||
{
|
||||
var homeTasks = plugins.Select(plugin => plugin.Metadata.HomeDisabled switch
|
||||
tasks = plugins.Select(plugin => plugin.Metadata.HomeDisabled switch
|
||||
{
|
||||
false => QueryTaskAsync(plugin, _updateSource.Token),
|
||||
true => Task.CompletedTask
|
||||
}).ToList();
|
||||
}).ToArray();
|
||||
|
||||
// Query history results for home page firstly so it will be put on top of the results
|
||||
if (Settings.ShowHistoryResultsForHomePage)
|
||||
{
|
||||
homeTasks.Add(QueryHistoryTaskAsync());
|
||||
await QueryHistoryTaskAsync();
|
||||
}
|
||||
|
||||
tasks = homeTasks.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1465,7 +1460,7 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
if (string.IsNullOrWhiteSpace(queryText))
|
||||
{
|
||||
return null;
|
||||
return QueryBuilder.Build(string.Empty, PluginManager.NonGlobalPlugins);
|
||||
}
|
||||
|
||||
var queryBuilder = new StringBuilder(queryText);
|
||||
|
|
|
|||
Loading…
Reference in a new issue