Skip to content

Commit 6ec183b

Browse files
Merge pull request #2088 from VictoriousRaptor/RequeryAfterKilling
Requery after killing a process
2 parents 5f4685a + 3ae656f commit 6ec183b

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public interface IPublicAPI
2020
/// </summary>
2121
/// <param name="query">query text</param>
2222
/// <param name="requery">
23-
/// force requery By default, Flow Launcher will not fire query if your query is same with existing one.
24-
/// Set this to true to force Flow Launcher requerying
23+
/// Force requery. By default, Flow Launcher will not fire query if your query is same with existing one.
24+
/// Set this to <see langword="true"/> to force Flow Launcher requerying
2525
/// </param>
2626
void ChangeQuery(string query, bool requery = false);
2727

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)