From 3ee52d7166ed26b22afd21aee503d2d8afae19bd Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 23 May 2025 14:16:56 +0800 Subject: [PATCH 1/3] Do not cancel tasks which is for clearing existing results --- Flow.Launcher/ViewModel/MainViewModel.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 48652f06358..f68086f057c 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -212,7 +212,8 @@ async Task UpdateActionAsync() await Task.Delay(20); while (channelReader.TryRead(out var item)) { - if (!item.Token.IsCancellationRequested) + // If this update task is for clearing existing results, we must need to add it to the queue + if (!item.Token.IsCancellationRequested || item.shouldClearExistingResults) queue[item.ID] = item; } @@ -1861,12 +1862,21 @@ public void UpdateResultView(ICollection resultsForUpdates) { if (!resultsForUpdates.Any()) return; + CancellationToken token; try { - // Don't know why sometimes even resultsForUpdates is empty, the method won't return; - token = resultsForUpdates.Select(r => r.Token).Distinct().SingleOrDefault(); + // If there are any update tasks for clearing existing results, we need to set token to default so that it will not be cancelled + if (resultsForUpdates.Any(r => r.shouldClearExistingResults)) + { + token = default; + } + else + { + // Don't know why sometimes even resultsForUpdates is empty, the method won't return; + token = resultsForUpdates.Select(r => r.Token).Distinct().SingleOrDefault(); + } } #if DEBUG catch From 445ca9a2fc6bf5555819736835310592dcf6a330 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 23 May 2025 14:33:03 +0800 Subject: [PATCH 2/3] Do not pass token to make sure it is handled --- Flow.Launcher/ViewModel/MainViewModel.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index f68086f057c..4898631b689 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1438,8 +1438,9 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) : _lastQuery = query; _previousIsHomeQuery = currentIsHomeQuery; + // If this update task is for clearing existing results, do not pass token to make sure it is handled if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query, - token, reSelect, shouldClearExistingResults))) + shouldClearExistingResults ? default : token, reSelect, shouldClearExistingResults))) { App.API.LogError(ClassName, "Unable to add item to Result Update Queue"); } @@ -1461,8 +1462,9 @@ void QueryHistoryTask(CancellationToken token) _lastQuery = query; _previousIsHomeQuery = currentIsHomeQuery; + // If this update task is for clearing existing results, do not pass token to make sure it is handled if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, _historyMetadata, query, - token, reSelect, shouldClearExistingResults))) + shouldClearExistingResults ? default : token, reSelect, shouldClearExistingResults))) { App.API.LogError(ClassName, "Unable to add item to Result Update Queue"); } From 634e829fc1026b3008e289347f7ec9cdf5835aab Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Fri, 23 May 2025 14:36:46 +0800 Subject: [PATCH 3/3] Improve code comments Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 4898631b689..f86e867abe2 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -212,7 +212,7 @@ async Task UpdateActionAsync() await Task.Delay(20); while (channelReader.TryRead(out var item)) { - // If this update task is for clearing existing results, we must need to add it to the queue + // If the update task is not canceled or requires clearing existing results, add it to the queue if (!item.Token.IsCancellationRequested || item.shouldClearExistingResults) queue[item.ID] = item; }