diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Languages/en.xaml
index 13655f998..2eee31745 100644
--- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Languages/en.xaml
+++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Languages/en.xaml
@@ -6,5 +6,6 @@
Kill running processes from Flow Launcher
kill all "{0}" processes
+ kill all instances
\ No newline at end of file
diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs
index d504ce842..e51d480c5 100644
--- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs
@@ -10,7 +10,7 @@ using Flow.Launcher.Infrastructure.Logger;
namespace Flow.Launcher.Plugin.ProcessKiller
{
- public class Main : IPlugin, IPluginI18n
+ public class Main : IPlugin, IPluginI18n, IContextMenu
{
private readonly HashSet _systemProcessList = new HashSet(){
"conhost",
@@ -58,6 +58,34 @@ namespace Flow.Launcher.Plugin.ProcessKiller
return _context.API.GetTranslation("flowlauncher_plugin_processkiller_plugin_description");
}
+ public List LoadContextMenus(Result result)
+ {
+ var menuOptions = new List();
+ var processPath = result.SubTitle;
+
+ // get all non-system processes whose file path matches that of the given result (processPath)
+ var similarProcesses = Process.GetProcesses()
+ .Where(p => !IsSystemProcess(p) && GetProcessFilename(p) == processPath);
+
+ menuOptions.Add(new Result
+ {
+ Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
+ SubTitle = processPath,
+ Action = _ =>
+ {
+ foreach (var p in similarProcesses)
+ {
+ KillProcess(p);
+ }
+
+ return true;
+ },
+ IcoPath = "Images/app.png"
+ });
+
+ return menuOptions;
+ }
+
private List CreateResultsFromProcesses(List processlist, string termToSearch)
{
var results = new List();
@@ -105,29 +133,30 @@ namespace Flow.Launcher.Plugin.ProcessKiller
}
return results;
+ }
- void KillProcess(Process p)
+ private void KillProcess(Process p)
+ {
+ try
{
- try
+ if (!p.HasExited)
{
- if (!p.HasExited)
- {
- p.Kill();
- }
- }
- catch (Exception e)
- {
- Log.Exception($"|ProcessKiller.CreateResultsFromProcesses|Failed to kill process {p.ProcessName}", e);
+ p.Kill();
}
}
+ catch (Exception e)
+ {
+ Log.Exception($"|ProcessKiller.CreateResultsFromProcesses|Failed to kill process {p.ProcessName}", e);
+ }
}
+
private List GetProcesslist(string termToSearch)
{
var processlist = new List();
foreach (var p in Process.GetProcesses())
{
- if (FilterSystemProcesses(p)) continue;
+ if (IsSystemProcess(p)) continue;
if (string.IsNullOrWhiteSpace(termToSearch))
{
@@ -145,14 +174,10 @@ namespace Flow.Launcher.Plugin.ProcessKiller
}
return processlist;
-
- bool FilterSystemProcesses(Process p)
- {
- var name = p.ProcessName.ToLower();
- return _systemProcessList.Contains(name);
- }
}
+ private bool IsSystemProcess(Process p) => _systemProcessList.Contains(p.ProcessName.ToLower());
+
internal class ProcessResult
{
public ProcessResult(Process process, int score)