From 28b8cb6013fb56de9d9946acc6a300af1e0883cf Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 4 May 2025 21:43:48 +0800 Subject: [PATCH] Improve distinguish between home query and global query --- Flow.Launcher.Core/Plugin/QueryBuilder.cs | 3 +-- Flow.Launcher.Plugin/Query.cs | 1 - Flow.Launcher/ViewModel/MainViewModel.cs | 17 +++++++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/QueryBuilder.cs b/Flow.Launcher.Core/Plugin/QueryBuilder.cs index 82745c239..fae821736 100644 --- a/Flow.Launcher.Core/Plugin/QueryBuilder.cs +++ b/Flow.Launcher.Core/Plugin/QueryBuilder.cs @@ -16,8 +16,7 @@ namespace Flow.Launcher.Core.Plugin Search = string.Empty, RawQuery = string.Empty, SearchTerms = Array.Empty(), - // must use null because we need to distinguish between home query and global query - ActionKeyword = null + ActionKeyword = string.Empty }; } diff --git a/Flow.Launcher.Plugin/Query.cs b/Flow.Launcher.Plugin/Query.cs index 7d98a4afe..c3eede4c6 100644 --- a/Flow.Launcher.Plugin/Query.cs +++ b/Flow.Launcher.Plugin/Query.cs @@ -53,7 +53,6 @@ namespace Flow.Launcher.Plugin /// /// The action keyword part of this query. /// For global plugins this value will be empty. - /// For home query this value will be null. /// public string ActionKeyword { get; init; } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 5fd8d395f..30df8250c 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -33,6 +33,7 @@ namespace Flow.Launcher.ViewModel private bool _isQueryRunning; private Query _lastQuery; + private bool _lastHomeQuery; private string _queryTextBeforeLeaveResults; private string _ignoredQueryText = null; @@ -1261,6 +1262,8 @@ namespace Flow.Launcher.ViewModel return; } + var homeQuery = query.RawQuery == string.Empty; + _updateSource = new CancellationTokenSource(); ProgressBarVisibility = Visibility.Hidden; @@ -1275,11 +1278,11 @@ namespace Flow.Launcher.ViewModel query.IsReQuery = isReQuery; // handle the exclusiveness of plugin using action keyword - RemoveOldQueryResults(query); + RemoveOldQueryResults(query, homeQuery); _lastQuery = query; + _lastHomeQuery = homeQuery; - var homeQuery = query.RawQuery == string.Empty; ICollection plugins = Array.Empty(); if (homeQuery) { @@ -1524,9 +1527,15 @@ namespace Flow.Launcher.ViewModel } } - private void RemoveOldQueryResults(Query query) + private void RemoveOldQueryResults(Query query, bool homeQuery) { - if (_lastQuery?.ActionKeyword != query?.ActionKeyword) + // If last or current query is home query, we need to clear the results + if (_lastHomeQuery || homeQuery) + { + Results.Clear(); + } + // If last and current query are not home query, we need to check action keyword + else if (_lastQuery?.ActionKeyword != query?.ActionKeyword) { Results.Clear(); }