Skip to content

Commit 3ae656f

Browse files
Requery after killing a process
1 parent 2147943 commit 3ae656f

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
5-
using System.Diagnostics;
6-
using System.Dynamic;
7-
using System.Runtime.InteropServices;
83
using Flow.Launcher.Infrastructure;
9-
using Flow.Launcher.Infrastructure.Logger;
4+
using System.Threading.Tasks;
105

116
namespace 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
}

Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void TryKill(Process p)
7979
}
8080
catch (Exception e)
8181
{
82-
Log.Exception($"|ProcessKiller.CreateResultsFromProcesses|Failed to kill process {p.ProcessName}", e);
82+
Log.Exception($"{nameof(ProcessHelper)}", $"Failed to kill process {p.ProcessName}", e);
8383
}
8484
}
8585

0 commit comments

Comments
 (0)