Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
_ = RegisterClockAndDateUpdateAsync();
}

private int cancelIndex = 0;

private void RegisterViewUpdate()
{
var resultUpdateChannel = Channel.CreateUnbounded<ResultsForUpdate>();
Expand All @@ -212,7 +214,7 @@
await Task.Delay(20);
while (channelReader.TryRead(out var item))
{
if (!item.Token.IsCancellationRequested)
if (item.shouldClearExistingResults || !item.Token.IsCancellationRequested)
queue[item.ID] = item;
}

Expand Down Expand Up @@ -1437,6 +1439,16 @@
_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)))
{
Expand Down Expand Up @@ -1842,7 +1854,7 @@
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
}

#pragma warning restore VSTHRD100 // Avoid async void methods

Check warning on line 1857 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`VSTHRD` is not a recognized word. (unrecognized-spelling)

/// <summary>
/// Save history, user selected records and top most records
Expand All @@ -1861,7 +1873,9 @@
{
if (!resultsForUpdates.Any())
return;

CancellationToken token;
var shouldClearExistingResults = resultsForUpdates.Any(r => r.shouldClearExistingResults);

try
{
Expand Down Expand Up @@ -1923,7 +1937,7 @@
// 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 = "<Pending>")]
Expand Down
13 changes: 11 additions & 2 deletions Flow.Launcher/ViewModel/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,21 @@ public void AddResults(List<Result> newRawResults, string resultId)
/// <summary>
/// To avoid deadlock, this method should not called from main thread
/// </summary>
public void AddResults(ICollection<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
public void AddResults(ICollection<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true, bool shouldClearExistingResults = false)
{
var newResults = NewResults(resultsForUpdates);

if (token.IsCancellationRequested)
return;
{
if (shouldClearExistingResults)
{
newResults = new List<ResultViewModel>();
}
else
{
return;
}
}

UpdateResults(newResults, reselect, token);
}
Expand Down
Loading