Skip to content

Commit 297643c

Browse files
committed
Revert all changes as master branch
1 parent deb0c21 commit 297643c

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

+19-16
Original file line numberDiff line numberDiff line change
@@ -1266,17 +1266,20 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12661266

12671267
var isHomeQuery = query.RawQuery == string.Empty;
12681268

1269-
_updateSource?.Dispose(); // Dispose old update source to fix possible cancellation issue
1270-
_updateSource = new CancellationTokenSource();
1271-
_updateToken = _updateSource.Token;
1269+
_updateSource?.Dispose();
1270+
1271+
var currentUpdateSource = new CancellationTokenSource();
1272+
_updateSource = currentUpdateSource;
1273+
var currentCancellationToken = _updateSource.Token;
1274+
_updateToken = currentCancellationToken;
12721275

12731276
ProgressBarVisibility = Visibility.Hidden;
12741277
_isQueryRunning = true;
12751278

12761279
// Switch to ThreadPool thread
12771280
await TaskScheduler.Default;
12781281

1279-
if (_updateToken.IsCancellationRequested) return;
1282+
if (currentCancellationToken.IsCancellationRequested) return;
12801283

12811284
// Update the query's IsReQuery property to true if this is a re-query
12821285
query.IsReQuery = isReQuery;
@@ -1325,19 +1328,19 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13251328
{
13261329
// Wait 15 millisecond for query change in global query
13271330
// if query changes, return so that it won't be calculated
1328-
await Task.Delay(15, _updateToken);
1329-
if (_updateToken.IsCancellationRequested) return;
1331+
await Task.Delay(15, currentCancellationToken);
1332+
if (currentCancellationToken.IsCancellationRequested) return;
13301333
}*/
13311334

1332-
_ = Task.Delay(200, _updateToken).ContinueWith(_ =>
1335+
_ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
13331336
{
13341337
// start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
13351338
if (_isQueryRunning)
13361339
{
13371340
ProgressBarVisibility = Visibility.Visible;
13381341
}
13391342
},
1340-
_updateToken,
1343+
currentCancellationToken,
13411344
TaskContinuationOptions.NotOnCanceled,
13421345
TaskScheduler.Default);
13431346

@@ -1348,21 +1351,21 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13481351
{
13491352
tasks = plugins.Select(plugin => plugin.Metadata.HomeDisabled switch
13501353
{
1351-
false => QueryTaskAsync(plugin, _updateToken),
1354+
false => QueryTaskAsync(plugin, currentCancellationToken),
13521355
true => Task.CompletedTask
13531356
}).ToArray();
13541357

13551358
// Query history results for home page firstly so it will be put on top of the results
13561359
if (Settings.ShowHistoryResultsForHomePage)
13571360
{
1358-
QueryHistoryTask();
1361+
QueryHistoryTask(currentCancellationToken);
13591362
}
13601363
}
13611364
else
13621365
{
13631366
tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
13641367
{
1365-
false => QueryTaskAsync(plugin, _updateToken),
1368+
false => QueryTaskAsync(plugin, currentCancellationToken),
13661369
true => Task.CompletedTask
13671370
}).ToArray();
13681371
}
@@ -1377,13 +1380,13 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13771380
// nothing to do here
13781381
}
13791382

1380-
if (_updateToken.IsCancellationRequested) return;
1383+
if (currentCancellationToken.IsCancellationRequested) return;
13811384

13821385
// this should happen once after all queries are done so progress bar should continue
13831386
// until the end of all querying
13841387
_isQueryRunning = false;
13851388

1386-
if (!_updateToken.IsCancellationRequested)
1389+
if (!currentCancellationToken.IsCancellationRequested)
13871390
{
13881391
// update to hidden if this is still the current query
13891392
ProgressBarVisibility = Visibility.Hidden;
@@ -1443,19 +1446,19 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
14431446
}
14441447
}
14451448

1446-
void QueryHistoryTask()
1449+
void QueryHistoryTask(CancellationToken token)
14471450
{
14481451
// Select last history results and revert its order to make sure last history results are on top
14491452
var historyItems = _history.Items.TakeLast(Settings.MaxHistoryResultsToShowForHomePage).Reverse();
14501453

14511454
var results = GetHistoryItems(historyItems);
14521455

1453-
if (_updateToken.IsCancellationRequested) return;
1456+
if (token.IsCancellationRequested) return;
14541457

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

14571460
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, _historyMetadata, query,
1458-
_updateToken)))
1461+
token)))
14591462
{
14601463
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
14611464
}

0 commit comments

Comments
 (0)