diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 48652f06358..c8a7e0a3670 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -194,6 +194,8 @@ public MainViewModel() _ = RegisterClockAndDateUpdateAsync(); } + private int cancelIndex = 0; + private void RegisterViewUpdate() { var resultUpdateChannel = Channel.CreateUnbounded(); @@ -212,7 +214,7 @@ async Task UpdateActionAsync() await Task.Delay(20); while (channelReader.TryRead(out var item)) { - if (!item.Token.IsCancellationRequested) + if (item.shouldClearExistingResults || !item.Token.IsCancellationRequested) queue[item.ID] = item; } @@ -1437,6 +1439,16 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) : _lastQuery = query; _previousIsHomeQuery = currentIsHomeQuery; + // Test: Assume first query task for clearing existing results is cancelled + if (shouldClearExistingResults) + { + cancelIndex++; + if (cancelIndex == 2) + { + currentUpdateSource.Cancel(); + } + } + if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query, token, reSelect, shouldClearExistingResults))) { @@ -1861,7 +1873,9 @@ public void UpdateResultView(ICollection resultsForUpdates) { if (!resultsForUpdates.Any()) return; + CancellationToken token; + var shouldClearExistingResults = resultsForUpdates.Any(r => r.shouldClearExistingResults); try { @@ -1923,7 +1937,7 @@ public void UpdateResultView(ICollection resultsForUpdates) // it should be the same for all results bool reSelect = resultsForUpdates.First().ReSelectFirstResult; - Results.AddResults(resultsForUpdates, token, reSelect); + Results.AddResults(resultsForUpdates, token, reSelect, shouldClearExistingResults); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "")] diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 9cd36e5c480..1c7a504da22 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -185,12 +185,21 @@ public void AddResults(List newRawResults, string resultId) /// /// To avoid deadlock, this method should not called from main thread /// - public void AddResults(ICollection resultsForUpdates, CancellationToken token, bool reselect = true) + public void AddResults(ICollection resultsForUpdates, CancellationToken token, bool reselect = true, bool shouldClearExistingResults = false) { var newResults = NewResults(resultsForUpdates); if (token.IsCancellationRequested) - return; + { + if (shouldClearExistingResults) + { + newResults = new List(); + } + else + { + return; + } + } UpdateResults(newResults, reselect, token); }