11using System ;
2+ using System . Collections ;
23using System . Collections . Generic ;
34using System . ComponentModel ;
45using System . Globalization ;
@@ -37,9 +38,6 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3738 private string _queryTextBeforeLeaveResults ;
3839 private string _ignoredQueryText ; // Used to ignore query text change when switching between context menu and query results
3940
40- private readonly object _shouldClearExistingResultsLock = new ( ) ;
41- private bool _shouldClearExistingResults ;
42-
4341 private readonly FlowLauncherJsonStorage < History > _historyItemsStorage ;
4442 private readonly FlowLauncherJsonStorage < UserSelectedRecord > _userSelectedRecordStorage ;
4543 private readonly FlowLauncherJsonStorageTopMostRecord _topMostRecord ;
@@ -216,7 +214,17 @@ async Task UpdateActionAsync()
216214 while ( channelReader . TryRead ( out var item ) )
217215 {
218216 if ( ! item . Token . IsCancellationRequested )
217+ {
218+ // Indicate if to clear existing results so to show only ones from plugins with action keywords
219+ var query = item . Query ;
220+ var currentIsHomeQuery = item . IsHomeQuery ;
221+ var shouldClearExistingResults = ShouldClearExistingResultsForQuery ( query , currentIsHomeQuery ) ;
222+ _lastQuery = item . Query ;
223+ _previousIsHomeQuery = currentIsHomeQuery ;
224+ item . ShouldClearExistingResults = shouldClearExistingResults ;
225+
219226 queue [ item . ID ] = item ;
227+ }
220228 }
221229
222230 UpdateResultView ( queue . Values ) ;
@@ -270,24 +278,8 @@ public void RegisterResultsUpdatedEvent()
270278
271279 App . API . LogDebug ( ClassName , $ "Update results for plugin <{ pair . Metadata . Name } >") ;
272280
273- // Home query does not support IResultUpdated, so this flag is false
274- var currentIsHomeQuery = false ;
275-
276- // Indicate if to clear existing results so to show only ones from plugins with action keywords
277- var shouldClearExistingResults = ShouldClearExistingResultsForQuery ( e . Query , currentIsHomeQuery ) ;
278- if ( shouldClearExistingResults )
279- {
280- // Setup the flag to clear existing results so that ResultsViewModel.NewResults will handle in the next update
281- lock ( _shouldClearExistingResultsLock )
282- {
283- _shouldClearExistingResults = true ;
284- }
285- }
286- _lastQuery = e . Query ;
287- _previousIsHomeQuery = currentIsHomeQuery ;
288-
289281 if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , pair . Metadata , e . Query ,
290- token ) ) )
282+ false , token ) ) )
291283 {
292284 App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
293285 }
@@ -1453,21 +1445,8 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
14531445
14541446 App . API . LogDebug ( ClassName , $ "Update results for plugin <{ plugin . Metadata . Name } >") ;
14551447
1456- // Indicate if to clear existing results so to show only ones from plugins with action keywords
1457- var shouldClearExistingResults = ShouldClearExistingResultsForQuery ( query , currentIsHomeQuery ) ;
1458- if ( shouldClearExistingResults )
1459- {
1460- // Setup the flag to clear existing results so that ResultsViewModel.NewResults will handle in the next update
1461- lock ( _shouldClearExistingResultsLock )
1462- {
1463- _shouldClearExistingResults = true ;
1464- }
1465- }
1466- _lastQuery = query ;
1467- _previousIsHomeQuery = currentIsHomeQuery ;
1468-
14691448 if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , plugin . Metadata , query ,
1470- token , reSelect ) ) )
1449+ currentIsHomeQuery , token , reSelect ) ) )
14711450 {
14721451 App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
14731452 }
@@ -1484,21 +1463,8 @@ void QueryHistoryTask(CancellationToken token)
14841463
14851464 App . API . LogDebug ( ClassName , $ "Update results for history") ;
14861465
1487- // Indicate if to clear existing results so to show only ones from plugins with action keywords
1488- var shouldClearExistingResults = ShouldClearExistingResultsForQuery ( query , currentIsHomeQuery ) ;
1489- if ( shouldClearExistingResults )
1490- {
1491- // Setup the flag to clear existing results so that ResultsViewModel.NewResults will handle in the next update
1492- lock ( _shouldClearExistingResultsLock )
1493- {
1494- _shouldClearExistingResults = true ;
1495- }
1496- }
1497- _lastQuery = query ;
1498- _previousIsHomeQuery = currentIsHomeQuery ;
1499-
15001466 if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( results , _historyMetadata , query ,
1501- token , reSelect ) ) )
1467+ currentIsHomeQuery , token , reSelect ) ) )
15021468 {
15031469 App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
15041470 }
@@ -1733,20 +1699,6 @@ internal bool ResultsSelected(ResultsViewModel results)
17331699 return selected ;
17341700 }
17351701
1736- internal bool CheckShouldClearExistingResultsAndReset ( )
1737- {
1738- lock ( _shouldClearExistingResultsLock )
1739- {
1740- if ( _shouldClearExistingResults )
1741- {
1742- _shouldClearExistingResults = false ;
1743- return true ;
1744- }
1745-
1746- return false ;
1747- }
1748- }
1749-
17501702 #endregion
17511703
17521704 #region Hotkey
@@ -1912,6 +1864,7 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
19121864 {
19131865 if ( ! resultsForUpdates . Any ( ) )
19141866 return ;
1867+
19151868 CancellationToken token ;
19161869
19171870 try
0 commit comments