diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index caa3fd00b..c22651738 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -278,11 +278,8 @@ namespace Flow.Launcher.Core.Plugin }; } - public static ICollection ValidPluginsForHomeQuery(Query query) + public static ICollection ValidPluginsForHomeQuery() { - if (query is not null) - return Array.Empty(); - return _homePlugins.ToList(); } diff --git a/Flow.Launcher.Core/Plugin/QueryBuilder.cs b/Flow.Launcher.Core/Plugin/QueryBuilder.cs index 0ef3f30f5..fae821736 100644 --- a/Flow.Launcher.Core/Plugin/QueryBuilder.cs +++ b/Flow.Launcher.Core/Plugin/QueryBuilder.cs @@ -8,10 +8,23 @@ namespace Flow.Launcher.Core.Plugin { public static Query Build(string text, Dictionary nonGlobalPlugins) { + // home query + if (string.IsNullOrEmpty(text)) + { + return new Query() + { + Search = string.Empty, + RawQuery = string.Empty, + SearchTerms = Array.Empty(), + 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; diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 8e708fbc4..517cf5323 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1220,31 +1220,21 @@ namespace Flow.Launcher.ViewModel _updateSource?.Cancel(); var query = await ConstructQueryAsync(QueryText, Settings.CustomShortcuts, Settings.BuiltinShortcuts); - var homeQuery = query == null; - ICollection plugins = Array.Empty(); 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 plugins = Array.Empty(); 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);