Merge pull request #2088 from VictoriousRaptor/RequeryAfterKilling

Requery after killing a process
This commit is contained in:
VictoriousRaptor 2023-05-01 02:10:55 +08:00 committed by GitHub
commit 6ec183b832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 20 deletions

View file

@ -20,8 +20,8 @@ namespace Flow.Launcher.Plugin
/// </summary>
/// <param name="query">query text</param>
/// <param name="requery">
/// force requery By default, Flow Launcher will not fire query if your query is same with existing one.
/// Set this to true to force Flow Launcher requerying
/// Force requery. By default, Flow Launcher will not fire query if your query is same with existing one.
/// Set this to <see langword="true"/> to force Flow Launcher requerying
/// </param>
void ChangeQuery(string query, bool requery = false);

View file

@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Dynamic;
using System.Runtime.InteropServices;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin.ProcessKiller
{
@ -23,13 +18,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
public List<Result> Query(Query query)
{
var termToSearch = query.Search;
var processlist = processHelper.GetMatchingProcesses(termToSearch);
return !processlist.Any()
? null
: CreateResultsFromProcesses(processlist, termToSearch);
return CreateResultsFromQuery(query);
}
public string GetTranslatedPluginTitle()
@ -50,7 +39,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
// get all non-system processes whose file path matches that of the given result (processPath)
var similarProcesses = processHelper.GetSimilarProcesses(processPath);
if (similarProcesses.Count() > 0)
if (similarProcesses.Any())
{
menuOptions.Add(new Result
{
@ -72,8 +61,16 @@ namespace Flow.Launcher.Plugin.ProcessKiller
return menuOptions;
}
private List<Result> CreateResultsFromProcesses(List<ProcessResult> processlist, string termToSearch)
private List<Result> CreateResultsFromQuery(Query query)
{
string termToSearch = query.Search;
var processlist = processHelper.GetMatchingProcesses(termToSearch);
if (!processlist.Any())
{
return null;
}
var results = new List<Result>();
foreach (var pr in processlist)
@ -92,6 +89,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
Action = (c) =>
{
processHelper.TryKill(p);
_ = DelayAndReQueryAsync(query.RawQuery); // Re-query after killing process to refresh process list
return true;
}
});
@ -116,7 +114,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
{
processHelper.TryKill(p.Process);
}
_ = DelayAndReQueryAsync(query.RawQuery); // Re-query after killing process to refresh process list
return true;
}
});
@ -124,5 +122,11 @@ namespace Flow.Launcher.Plugin.ProcessKiller
return sortedResults;
}
private static async Task DelayAndReQueryAsync(string query)
{
await Task.Delay(500);
_context.API.ChangeQuery(query, true);
}
}
}

View file

@ -79,7 +79,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
}
catch (Exception e)
{
Log.Exception($"|ProcessKiller.CreateResultsFromProcesses|Failed to kill process {p.ProcessName}", e);
Log.Exception($"{nameof(ProcessHelper)}", $"Failed to kill process {p.ProcessName}", e);
}
}