1- using System ;
2- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
32using System . Linq ;
4- using System . Text ;
5- using System . Diagnostics ;
6- using System . Dynamic ;
7- using System . Runtime . InteropServices ;
83using Flow . Launcher . Infrastructure ;
9- using Flow . Launcher . Infrastructure . Logger ;
4+ using System . Threading . Tasks ;
105
116namespace Flow . Launcher . Plugin . ProcessKiller
127{
@@ -23,13 +18,7 @@ public void Init(PluginInitContext context)
2318
2419 public List < Result > Query ( Query query )
2520 {
26- var termToSearch = query . Search ;
27-
28- var processlist = processHelper . GetMatchingProcesses ( termToSearch ) ;
29-
30- return ! processlist . Any ( )
31- ? null
32- : CreateResultsFromProcesses ( processlist , termToSearch ) ;
21+ return CreateResultsFromQuery ( query ) ;
3322 }
3423
3524 public string GetTranslatedPluginTitle ( )
@@ -50,7 +39,7 @@ public List<Result> LoadContextMenus(Result result)
5039 // get all non-system processes whose file path matches that of the given result (processPath)
5140 var similarProcesses = processHelper . GetSimilarProcesses ( processPath ) ;
5241
53- if ( similarProcesses . Count ( ) > 0 )
42+ if ( similarProcesses . Any ( ) )
5443 {
5544 menuOptions . Add ( new Result
5645 {
@@ -72,8 +61,16 @@ public List<Result> LoadContextMenus(Result result)
7261 return menuOptions ;
7362 }
7463
75- private List < Result > CreateResultsFromProcesses ( List < ProcessResult > processlist , string termToSearch )
64+ private List < Result > CreateResultsFromQuery ( Query query )
7665 {
66+ string termToSearch = query . Search ;
67+ var processlist = processHelper . GetMatchingProcesses ( termToSearch ) ;
68+
69+ if ( ! processlist . Any ( ) )
70+ {
71+ return null ;
72+ }
73+
7774 var results = new List < Result > ( ) ;
7875
7976 foreach ( var pr in processlist )
@@ -92,6 +89,7 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
9289 Action = ( c ) =>
9390 {
9491 processHelper . TryKill ( p ) ;
92+ _ = DelayAndReQueryAsync ( query . RawQuery ) ; // Re-query after killing process to refresh process list
9593 return true ;
9694 }
9795 } ) ;
@@ -116,13 +114,19 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
116114 {
117115 processHelper . TryKill ( p . Process ) ;
118116 }
119-
117+ _ = DelayAndReQueryAsync ( query . RawQuery ) ; // Re-query after killing process to refresh process list
120118 return true ;
121119 }
122120 } ) ;
123121 }
124122
125123 return sortedResults ;
126124 }
125+
126+ private static async Task DelayAndReQueryAsync ( string query )
127+ {
128+ await Task . Delay ( 500 ) ;
129+ _context . API . ChangeQuery ( query , true ) ;
130+ }
127131 }
128132}
0 commit comments