Skip to content

Commit 1e4bc07

Browse files
authored
Merge pull request #167 from JohnTheGr8/processkiller_enhancements
plugin/ProcessKiller: enhancements to the kill-all functionality
2 parents 82ebbcb + b1ca71b commit 1e4bc07

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Plugins/Flow.Launcher.Plugin.ProcessKiller/Languages/en.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_name">Process Killer</system:String>
66
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_description">Kill running processes from Flow Launcher</system:String>
77

8-
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all">kill all "{0}" processes</system:String>
8+
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all">kill all instances of "{0}"</system:String>
9+
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all_count">kill {0} processes</system:String>
910
<system:String x:Key="flowlauncher_plugin_processkiller_kill_instances">kill all instances</system:String>
1011

1112
</ResourceDictionary>

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,24 @@ public List<Result> LoadContextMenus(Result result)
5252
// get all non-system processes whose file path matches that of the given result (processPath)
5353
var similarProcesses = processHelper.GetSimilarProcesses(processPath);
5454

55-
menuOptions.Add(new Result
55+
if (similarProcesses.Count() > 0)
5656
{
57-
Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
58-
SubTitle = processPath,
59-
Action = _ =>
57+
menuOptions.Add(new Result
6058
{
61-
foreach (var p in similarProcesses)
59+
Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
60+
SubTitle = processPath,
61+
Action = _ =>
6262
{
63-
processHelper.TryKill(p);
64-
}
63+
foreach (var p in similarProcesses)
64+
{
65+
processHelper.TryKill(p);
66+
}
6567

66-
return true;
67-
},
68-
IcoPath = processPath
69-
});
68+
return true;
69+
},
70+
IcoPath = processPath
71+
});
72+
}
7073

7174
return menuOptions;
7275
}
@@ -86,6 +89,7 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
8689
SubTitle = path,
8790
TitleHighlightData = StringMatcher.FuzzySearch(termToSearch, p.ProcessName).MatchData,
8891
Score = pr.Score,
92+
ContextData = p.ProcessName,
8993
Action = (c) =>
9094
{
9195
processHelper.TryKill(p);
@@ -98,14 +102,14 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
98102

99103
// When there are multiple results AND all of them are instances of the same executable
100104
// add a quick option to kill them all at the top of the results.
101-
var firstResult = sortedResults.FirstOrDefault()?.SubTitle;
102-
if (processlist.Count > 1 && !string.IsNullOrEmpty(termToSearch) && sortedResults.All(r => r.SubTitle == firstResult))
105+
var firstResult = sortedResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.SubTitle));
106+
if (processlist.Count > 1 && !string.IsNullOrEmpty(termToSearch) && sortedResults.All(r => r.SubTitle == firstResult?.SubTitle))
103107
{
104108
sortedResults.Insert(1, new Result()
105109
{
106-
IcoPath = "Images/app.png",
107-
Title = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), termToSearch),
108-
SubTitle = "",
110+
IcoPath = firstResult?.IcoPath,
111+
Title = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), firstResult?.ContextData),
112+
SubTitle = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all_count"), processlist.Count),
109113
Score = 200,
110114
Action = (c) =>
111115
{

0 commit comments

Comments
 (0)