1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Linq ;
4
- using System . Text ;
5
- using System . Diagnostics ;
6
- using System . Dynamic ;
7
- using System . Runtime . InteropServices ;
8
3
using Flow . Launcher . Infrastructure ;
9
- using Flow . Launcher . Infrastructure . Logger ;
4
+ using System . Threading . Tasks ;
10
5
11
6
namespace Flow . Launcher . Plugin . ProcessKiller
12
7
{
@@ -23,13 +18,7 @@ public void Init(PluginInitContext context)
23
18
24
19
public List < Result > Query ( Query query )
25
20
{
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 ) ;
33
22
}
34
23
35
24
public string GetTranslatedPluginTitle ( )
@@ -50,7 +39,7 @@ public List<Result> LoadContextMenus(Result result)
50
39
// get all non-system processes whose file path matches that of the given result (processPath)
51
40
var similarProcesses = processHelper . GetSimilarProcesses ( processPath ) ;
52
41
53
- if ( similarProcesses . Count ( ) > 0 )
42
+ if ( similarProcesses . Any ( ) )
54
43
{
55
44
menuOptions . Add ( new Result
56
45
{
@@ -72,8 +61,16 @@ public List<Result> LoadContextMenus(Result result)
72
61
return menuOptions ;
73
62
}
74
63
75
- private List < Result > CreateResultsFromProcesses ( List < ProcessResult > processlist , string termToSearch )
64
+ private List < Result > CreateResultsFromQuery ( Query query )
76
65
{
66
+ string termToSearch = query . Search ;
67
+ var processlist = processHelper . GetMatchingProcesses ( termToSearch ) ;
68
+
69
+ if ( ! processlist . Any ( ) )
70
+ {
71
+ return null ;
72
+ }
73
+
77
74
var results = new List < Result > ( ) ;
78
75
79
76
foreach ( var pr in processlist )
@@ -92,6 +89,7 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
92
89
Action = ( c ) =>
93
90
{
94
91
processHelper . TryKill ( p ) ;
92
+ _ = DelayAndReQueryAsync ( query . RawQuery ) ; // Re-query after killing process to refresh process list
95
93
return true ;
96
94
}
97
95
} ) ;
@@ -116,13 +114,19 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
116
114
{
117
115
processHelper . TryKill ( p . Process ) ;
118
116
}
119
-
117
+ _ = DelayAndReQueryAsync ( query . RawQuery ) ; // Re-query after killing process to refresh process list
120
118
return true ;
121
119
}
122
120
} ) ;
123
121
}
124
122
125
123
return sortedResults ;
126
124
}
125
+
126
+ private static async Task DelayAndReQueryAsync ( string query )
127
+ {
128
+ await Task . Delay ( 500 ) ;
129
+ _context . API . ChangeQuery ( query , true ) ;
130
+ }
127
131
}
128
132
}
0 commit comments