diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 48652f06358..f86e867abe2 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 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; } @@ -1437,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"); } @@ -1460,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"); } @@ -1861,12 +1864,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