Fix possible result update issue for plugins with IResultUpdate interface

This commit is contained in:
Jack251970 2024-12-08 09:24:17 +08:00
parent 304f98e9ed
commit 0c43ea9379

View file

@ -1447,26 +1447,35 @@ namespace Flow.Launcher.ViewModel
}
#endif
foreach (var metaResults in resultsForUpdates)
try
{
foreach (var result in metaResults.Results)
foreach (var metaResults in resultsForUpdates)
{
if (_topMostRecord.IsTopMost(result))
foreach (var result in metaResults.Results)
{
result.Score = int.MaxValue;
}
else
{
var priorityScore = metaResults.Metadata.Priority * 150;
result.Score += _userSelectedRecord.GetSelectedCount(result) + priorityScore;
if (_topMostRecord.IsTopMost(result))
{
result.Score = int.MaxValue;
}
else
{
var priorityScore = metaResults.Metadata.Priority * 150;
result.Score += _userSelectedRecord.GetSelectedCount(result) + priorityScore;
}
}
}
// it should be the same for all results
bool reSelect = resultsForUpdates.First().ReSelectFirstResult;
Results.AddResults(resultsForUpdates, token, reSelect);
}
catch (InvalidOperationException e)
{
// Plugin with IResultUpdate interface can somtimes throw this exception
// Collection was modified; enumeration operation may not execute
Log.Exception($"{nameof(MainViewModel)}.{nameof(UpdateResultView)}|UpdateResultView failed", e);
}
// it should be the same for all results
bool reSelect = resultsForUpdates.First().ReSelectFirstResult;
Results.AddResults(resultsForUpdates, token, reSelect);
}
#endregion