Skip to content

Commit 0c43ea9

Browse files
committed
Fix possible result update issue for plugins with IResultUpdate interface
1 parent 304f98e commit 0c43ea9

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,26 +1447,35 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
14471447
}
14481448
#endif
14491449

1450-
foreach (var metaResults in resultsForUpdates)
1450+
try
14511451
{
1452-
foreach (var result in metaResults.Results)
1452+
foreach (var metaResults in resultsForUpdates)
14531453
{
1454-
if (_topMostRecord.IsTopMost(result))
1455-
{
1456-
result.Score = int.MaxValue;
1457-
}
1458-
else
1454+
foreach (var result in metaResults.Results)
14591455
{
1460-
var priorityScore = metaResults.Metadata.Priority * 150;
1461-
result.Score += _userSelectedRecord.GetSelectedCount(result) + priorityScore;
1456+
if (_topMostRecord.IsTopMost(result))
1457+
{
1458+
result.Score = int.MaxValue;
1459+
}
1460+
else
1461+
{
1462+
var priorityScore = metaResults.Metadata.Priority * 150;
1463+
result.Score += _userSelectedRecord.GetSelectedCount(result) + priorityScore;
1464+
}
14621465
}
14631466
}
1464-
}
14651467

1466-
// it should be the same for all results
1467-
bool reSelect = resultsForUpdates.First().ReSelectFirstResult;
1468+
// it should be the same for all results
1469+
bool reSelect = resultsForUpdates.First().ReSelectFirstResult;
14681470

1469-
Results.AddResults(resultsForUpdates, token, reSelect);
1471+
Results.AddResults(resultsForUpdates, token, reSelect);
1472+
}
1473+
catch (InvalidOperationException e)
1474+
{
1475+
// Plugin with IResultUpdate interface can somtimes throw this exception
1476+
// Collection was modified; enumeration operation may not execute
1477+
Log.Exception($"{nameof(MainViewModel)}.{nameof(UpdateResultView)}|UpdateResultView failed", e);
1478+
}
14701479
}
14711480

14721481
#endregion

0 commit comments

Comments
 (0)