Skip to content

Fix history results clear logic & Make sure results cleared #3525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void OnSourceInitialized(object sender, EventArgs e)
Win32Helper.DisableControlBox(this);
}

private async void OnLoaded(object sender, RoutedEventArgs _)
private void OnLoaded(object sender, RoutedEventArgs _)
{
// Check first launch
if (_settings.FirstLaunch)
Expand Down
23 changes: 20 additions & 3 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,6 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
// Update the query's IsReQuery property to true if this is a re-query
query.IsReQuery = isReQuery;



ICollection<PluginPair> plugins = Array.Empty<PluginPair>();
if (currentIsHomeQuery)
{
Expand Down Expand Up @@ -1342,6 +1340,7 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b

// plugins are ICollection, meaning LINQ will get the Count and preallocate Array

var resultsCleared = false;
Task[] tasks;
if (currentIsHomeQuery)
{
Expand Down Expand Up @@ -1376,6 +1375,9 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
// nothing to do here
}

// If results are not cleared, we need to clear the results
if (!resultsCleared) Results.Clear();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? This could cause unexplained/unexpected flicker

Copy link
Member Author

@Jack251970 Jack251970 May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must need it. This is used to make sure results are cleared when there are not any update tasks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about one situation. Home page feature is off and you just change query text from e to empty. You will find the results will not be cleared because there are not any update tasks. So we should force call Results.Clear() here when it is not be called in QueryResult or QueryHistory functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say not any update task are you referring to one example where you toggle off home page in settings and results are not cleared?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me give you one demo video

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjw24 It seems that I have issues when uploading video here. Please see more in Discord.

if (currentCancellationToken.IsCancellationRequested) return;

// this should happen once after all queries are done so progress bar should continue
Expand Down Expand Up @@ -1445,6 +1447,11 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
{
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
}
else
{
// Only update the clear flag when we successfully write to the channel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually get failure writes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still take that into consideration.

Copy link
Member

@jjw24 jjw24 May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm we probably should take into consideration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that will cause issue as below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

resultsCleared = true;
}
}

void QueryHistoryTask(CancellationToken token)
Expand All @@ -1458,11 +1465,21 @@ void QueryHistoryTask(CancellationToken token)

App.API.LogDebug(ClassName, $"Update results for history");

// Indicate if to clear existing results so to show only ones from plugins with action keywords
var shouldClearExistingResults = ShouldClearExistingResults(query, currentIsHomeQuery);
_lastQuery = query;
_previousIsHomeQuery = currentIsHomeQuery;

if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, _historyMetadata, query,
token)))
token, reSelect, shouldClearExistingResults)))
{
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
}
else
{
// Only update the clear flag when we successfully write to the channel
resultsCleared = true;
}
}
}

Expand Down
Loading