mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix progress query management and thread safety (#4135)
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
parent
516059e390
commit
0717933459
1 changed files with 11 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
|
@ -37,7 +38,7 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
private Query _lastQuery;
|
||||
private bool _previousIsHomeQuery;
|
||||
private Query _progressQuery; // Used for QueryResultAsync
|
||||
private readonly ConcurrentDictionary<Guid, Query> _progressQueryDict = new(); // Used for QueryResultAsync
|
||||
private Query _updateQuery; // Used for ResultsUpdated
|
||||
private string _queryTextBeforeLeaveResults;
|
||||
private string _ignoredQueryText; // Used to ignore query text change when switching between context menu and query results
|
||||
|
|
@ -1415,6 +1416,9 @@ namespace Flow.Launcher.ViewModel
|
|||
return;
|
||||
}
|
||||
|
||||
// Create a Guid for this update session so that we can filter out in progress checking
|
||||
var updateGuid = Guid.NewGuid();
|
||||
|
||||
try
|
||||
{
|
||||
_updateSource?.Dispose();
|
||||
|
|
@ -1426,7 +1430,7 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
ProgressBarVisibility = Visibility.Hidden;
|
||||
|
||||
_progressQuery = query;
|
||||
_progressQueryDict.TryAdd(updateGuid, query);
|
||||
_updateQuery = query;
|
||||
|
||||
// Switch to ThreadPool thread
|
||||
|
|
@ -1481,7 +1485,8 @@ namespace Flow.Launcher.ViewModel
|
|||
_ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
|
||||
{
|
||||
// start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
|
||||
if (_progressQuery != null && _progressQuery.OriginalQuery == query.OriginalQuery)
|
||||
if (_progressQueryDict.TryGetValue(updateGuid, out var progressQuery) &&
|
||||
progressQuery.OriginalQuery == query.OriginalQuery)
|
||||
{
|
||||
ProgressBarVisibility = Visibility.Visible;
|
||||
}
|
||||
|
|
@ -1537,7 +1542,7 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
// this should happen once after all queries are done so progress bar should continue
|
||||
// until the end of all querying
|
||||
_progressQuery = null;
|
||||
_progressQueryDict.Remove(updateGuid, out _);
|
||||
|
||||
if (!currentCancellationToken.IsCancellationRequested)
|
||||
{
|
||||
|
|
@ -1547,8 +1552,8 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
finally
|
||||
{
|
||||
// this make sures progress query is null when this query is canceled
|
||||
_progressQuery = null;
|
||||
// this ensures the query is removed from the progress tracking dictionary when this query is canceled or completes
|
||||
_progressQueryDict.Remove(updateGuid, out _);
|
||||
}
|
||||
|
||||
// Local function
|
||||
|
|
|
|||
Loading…
Reference in a new issue