Skip to content

Commit 3abc77f

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into RenderImprovement
# Conflicts: # Flow.Launcher/ViewModel/MainViewModel.cs
1 parent 1cbe1a9 commit 3abc77f

File tree

1 file changed

+28
-59
lines changed

1 file changed

+28
-59
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private void InitializeKeyCommands()
244244

245245
public string QueryText
246246
{
247-
get { return _queryText; }
247+
get => _queryText;
248248
set
249249
{
250250
_queryText = value;
@@ -444,28 +444,26 @@ private void QueryResults()
444444
var plugins = PluginManager.ValidPluginsForQuery(query);
445445

446446
Task.Run(async () =>
447-
{
448-
if (query.ActionKeyword == Plugin.Query.GlobalPluginWildcardSign)
449-
{
450-
// Wait 45 millisecond for query change in global query
451-
// if query changes, return so that it won't be calculated
452-
await Task.Delay(45, currentCancellationToken);
453-
if (currentCancellationToken.IsCancellationRequested)
454-
return;
455-
}
456-
457-
_ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
458447
{
459-
// start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
460-
if (!currentCancellationToken.IsCancellationRequested && _isQueryRunning)
448+
if (query.ActionKeyword == Plugin.Query.GlobalPluginWildcardSign)
461449
{
462-
ProgressBarVisibility = Visibility.Visible;
450+
// Wait 45 millisecond for query change in global query
451+
// if query changes, return so that it won't be calculated
452+
await Task.Delay(45, currentCancellationToken);
453+
if (currentCancellationToken.IsCancellationRequested)
454+
return;
463455
}
464-
}, currentCancellationToken);
465456

466-
var plugins = PluginManager.ValidPluginsForQuery(query);
467-
Task.Run(async () =>
468-
{
457+
_ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
458+
{
459+
// start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
460+
if (!currentCancellationToken.IsCancellationRequested && _isQueryRunning)
461+
{
462+
ProgressBarVisibility = Visibility.Visible;
463+
}
464+
}, currentCancellationToken);
465+
466+
var plugins = PluginManager.ValidPluginsForQuery(query);
469467
// so looping will stop once it was cancelled
470468

471469
Task[] tasks = new Task[plugins.Count];
@@ -475,7 +473,7 @@ private void QueryResults()
475473
{
476474
if (!plugins[i].Metadata.Disabled)
477475
{
478-
tasks[i] = QueryTask(plugins[i], query, currentCancellationToken);
476+
tasks[i] = QueryTask(plugins[i]);
479477
}
480478
else
481479
{
@@ -491,6 +489,9 @@ private void QueryResults()
491489
// nothing to do here
492490
}
493491

492+
if (currentCancellationToken.IsCancellationRequested)
493+
return;
494+
494495
// this should happen once after all queries are done so progress bar should continue
495496
// until the end of all querying
496497
_isQueryRunning = false;
@@ -501,28 +502,20 @@ private void QueryResults()
501502
}
502503

503504
// Local function
504-
async Task QueryTask(PluginPair plugin, Query query, CancellationToken token)
505+
async Task QueryTask(PluginPair plugin)
505506
{
506507
// Since it is wrapped within a Task.Run, the synchronous context is null
507508
// Task.Yield will force it to run in ThreadPool
508509
await Task.Yield();
509510

510-
var results = await PluginManager.QueryForPlugin(plugin, query, token);
511+
var results = await PluginManager.QueryForPlugin(plugin, query, currentCancellationToken);
511512
if (!currentCancellationToken.IsCancellationRequested)
512-
UpdateResultView(results, plugin.Metadata, query);
513+
_resultsUpdateQueue.Post(new ResultsForUpdate(results, plugin.Metadata, query,
514+
currentCancellationToken));
513515
}
514-
}, currentCancellationToken).ContinueWith(
515-
t => Log.Exception("|MainViewModel|Plugins Query Exceptions", t.Exception),
516+
}, currentCancellationToken)
517+
.ContinueWith(t => Log.Exception("|MainViewModel|Plugins Query Exceptions", t.Exception),
516518
TaskContinuationOptions.OnlyOnFaulted);
517-
518-
519-
else
520-
521-
{
522-
Results.Clear();
523-
Results.Visbility = Visibility.Collapsed;
524-
}
525-
}
526519
}
527520

528521

@@ -786,7 +779,7 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
786779
}
787780
else
788781
{
789-
var priorityScore = metaResults.Metadata.Priority * 50;
782+
var priorityScore = metaResults.Metadata.Priority * 150;
790783
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5 + priorityScore;
791784
}
792785
}
@@ -795,30 +788,6 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
795788
Results.AddResults(resultsForUpdates, token);
796789
}
797790

798-
/// <summary>U
799-
/// To avoid deadlock, this method should not called from main thread
800-
/// </summary>
801-
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
802-
{
803-
foreach (var result in list)
804-
{
805-
if (_topMostRecord.IsTopMost(result))
806-
{
807-
result.Score = int.MaxValue;
808-
}
809-
else
810-
{
811-
var priorityScore = metadata.Priority * 150;
812-
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5 + priorityScore;
813-
}
814-
}
815-
816-
if (originQuery.RawQuery == _lastQuery.RawQuery)
817-
{
818-
Results.AddResults(list, metadata.ID);
819-
}
820-
}
821-
822791
#endregion
823792
}
824793
}

0 commit comments

Comments
 (0)