Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.ProcessKiller/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_name">Process Killer</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_description">Kill running processes from Flow Launcher</system:String>

<system:String x:Key="flowlauncher_plugin_processkiller_kill_all">kill all "{0}" processes</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all">kill all instances of "{0}"</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all_count">kill {0} processes</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_kill_instances">kill all instances</system:String>

</ResourceDictionary>
36 changes: 20 additions & 16 deletions Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,24 @@ public List<Result> LoadContextMenus(Result result)
// get all non-system processes whose file path matches that of the given result (processPath)
var similarProcesses = processHelper.GetSimilarProcesses(processPath);

menuOptions.Add(new Result
if (similarProcesses.Count() > 0)
{
Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
SubTitle = processPath,
Action = _ =>
menuOptions.Add(new Result
{
foreach (var p in similarProcesses)
Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
SubTitle = processPath,
Action = _ =>
{
processHelper.TryKill(p);
}
foreach (var p in similarProcesses)
{
processHelper.TryKill(p);
}

return true;
},
IcoPath = processPath
});
return true;
},
IcoPath = processPath
});
}

return menuOptions;
}
Expand All @@ -86,6 +89,7 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,
SubTitle = path,
TitleHighlightData = StringMatcher.FuzzySearch(termToSearch, p.ProcessName).MatchData,
Score = pr.Score,
ContextData = p.ProcessName,
Action = (c) =>
{
processHelper.TryKill(p);
Expand All @@ -98,14 +102,14 @@ private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist,

// When there are multiple results AND all of them are instances of the same executable
// add a quick option to kill them all at the top of the results.
var firstResult = sortedResults.FirstOrDefault()?.SubTitle;
if (processlist.Count > 1 && !string.IsNullOrEmpty(termToSearch) && sortedResults.All(r => r.SubTitle == firstResult))
var firstResult = sortedResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.SubTitle));
if (processlist.Count > 1 && !string.IsNullOrEmpty(termToSearch) && sortedResults.All(r => r.SubTitle == firstResult?.SubTitle))
{
sortedResults.Insert(1, new Result()
{
IcoPath = "Images/app.png",
Title = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), termToSearch),
SubTitle = "",
IcoPath = firstResult?.IcoPath,
Title = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), firstResult?.ContextData),
SubTitle = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all_count"), processlist.Count),
Score = 200,
Action = (c) =>
{
Expand Down