Skip to content

Commit 1aa119d

Browse files
committed
fix some legacy code from #195
1 parent cd92512 commit 1aa119d

File tree

2 files changed

+12
-38
lines changed

2 files changed

+12
-38
lines changed

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public void ShowMsg(string title, string subTitle, string iconPath, bool useMain
9292
{
9393
Application.Current.Dispatcher.Invoke(() =>
9494
{
95+
useMainWindowAsOwner = false;
9596
var msg = useMainWindowAsOwner ? new Msg { Owner = Application.Current.MainWindow } : new Msg();
9697
msg.Show(title, subTitle, iconPath);
9798
});

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -139,39 +139,9 @@ public void KeepResultsExcept(PluginMetadata metadata)
139139
/// </summary>
140140
public void AddResults(List<Result> newRawResults, string resultId)
141141
{
142-
lock (_collectionLock)
143-
{
144-
var newResults = NewResults(newRawResults, resultId);
145-
146-
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
147-
// fix selected index flow
148-
var updateTask = Task.Run(() =>
149-
{
150-
// update UI in one run, so it can avoid UI flickering
151-
152-
Results.Update(newResults);
153-
if (Results.Any())
154-
SelectedItem = Results[0];
155-
});
156-
if (!updateTask.Wait(300))
157-
{
158-
updateTask.Dispose();
159-
throw new TimeoutException("Update result use too much time.");
160-
}
142+
var newResults = NewResults(newRawResults, resultId);
161143

162-
}
163-
164-
if (Visbility != Visibility.Visible && Results.Count > 0)
165-
{
166-
Margin = new Thickness { Top = 8 };
167-
SelectedIndex = 0;
168-
Visbility = Visibility.Visible;
169-
}
170-
else
171-
{
172-
Margin = new Thickness { Top = 0 };
173-
Visbility = Visibility.Collapsed;
174-
}
144+
UpdateResults(newResults);
175145
}
176146
/// <summary>
177147
/// To avoid deadlock, this method should not called from main thread
@@ -181,10 +151,15 @@ public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, Cancella
181151
var newResults = NewResults(resultsForUpdates);
182152
if (token.IsCancellationRequested)
183153
return;
154+
UpdateResults(newResults, token);
155+
156+
}
157+
158+
private void UpdateResults(List<ResultViewModel> newResults, CancellationToken token = default)
159+
{
184160
lock (_collectionLock)
185161
{
186162
// update UI in one run, so it can avoid UI flickering
187-
188163
Results.Update(newResults, token);
189164
if (Results.Any())
190165
SelectedItem = Results[0];
@@ -202,7 +177,6 @@ public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, Cancella
202177
Visbility = Visibility.Collapsed;
203178
break;
204179
}
205-
206180
}
207181

208182
private List<ResultViewModel> NewResults(List<Result> newRawResults, string resultId)
@@ -212,10 +186,10 @@ private List<ResultViewModel> NewResults(List<Result> newRawResults, string resu
212186

213187
var results = Results as IEnumerable<ResultViewModel>;
214188

215-
var newResults = newRawResults.Select(r => new ResultViewModel(r, _settings)).ToList();
189+
var newResults = newRawResults.Select(r => new ResultViewModel(r, _settings));
216190

217191
return results.Where(r => r.Result.PluginID != resultId)
218-
.Concat(results.Intersect(newResults).Union(newResults))
192+
.Concat(newResults)
219193
.OrderByDescending(r => r.Result.Score)
220194
.ToList();
221195
}
@@ -228,8 +202,7 @@ private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsFo
228202
var results = Results as IEnumerable<ResultViewModel>;
229203

230204
return results.Where(r => r != null && !resultsForUpdates.Any(u => u.Metadata.ID == r.Result.PluginID))
231-
.Concat(
232-
resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
205+
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
233206
.OrderByDescending(rv => rv.Result.Score)
234207
.ToList();
235208
}

0 commit comments

Comments
 (0)