mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use score bump & Search window title
This commit is contained in:
parent
6bc69b17cf
commit
8ee2d4852e
2 changed files with 36 additions and 15 deletions
|
|
@ -64,9 +64,9 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
|
|
||||||
private List<Result> CreateResultsFromQuery(Query query)
|
private List<Result> CreateResultsFromQuery(Query query)
|
||||||
{
|
{
|
||||||
string termToSearch = query.Search;
|
var searchTerm = query.Search;
|
||||||
var processList = processHelper.GetMatchingProcesses(termToSearch);
|
var processWindowTitle = ProcessHelper.GetProcessesWithNonEmptyWindowTitle();
|
||||||
var processWithNonEmptyMainWindowTitleList = ProcessHelper.GetProcessesWithNonEmptyWindowTitle();
|
var processList = processHelper.GetMatchingProcesses(searchTerm, processWindowTitle);
|
||||||
|
|
||||||
if (!processList.Any())
|
if (!processList.Any())
|
||||||
{
|
{
|
||||||
|
|
@ -74,18 +74,28 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = new List<Result>();
|
var results = new List<Result>();
|
||||||
|
|
||||||
foreach (var pr in processList)
|
foreach (var pr in processList)
|
||||||
{
|
{
|
||||||
var p = pr.Process;
|
var p = pr.Process;
|
||||||
var path = processHelper.TryGetProcessFilename(p);
|
var path = processHelper.TryGetProcessFilename(p);
|
||||||
|
var title = p.ProcessName + " - " + p.Id;
|
||||||
|
var score = pr.Score;
|
||||||
|
if (processWindowTitle.TryGetValue(p.Id, out var mainWindowTitle))
|
||||||
|
{
|
||||||
|
title = mainWindowTitle;
|
||||||
|
if (string.IsNullOrWhiteSpace(searchTerm))
|
||||||
|
{
|
||||||
|
// Add score to prioritize processes with visible windows
|
||||||
|
score += 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
results.Add(new Result()
|
results.Add(new Result()
|
||||||
{
|
{
|
||||||
IcoPath = path,
|
IcoPath = path,
|
||||||
Title = processWithNonEmptyMainWindowTitleList.TryGetValue(p.Id, out var mainWindowTitle) ? mainWindowTitle : p.ProcessName + " - " + p.Id,
|
Title = title,
|
||||||
SubTitle = path,
|
SubTitle = path,
|
||||||
TitleHighlightData = StringMatcher.FuzzySearch(termToSearch, p.ProcessName).MatchData,
|
TitleHighlightData = StringMatcher.FuzzySearch(searchTerm, p.ProcessName).MatchData,
|
||||||
Score = pr.Score,
|
Score = score,
|
||||||
ContextData = new RunningProcessInfo(p.ProcessName, mainWindowTitle),
|
ContextData = new RunningProcessInfo(p.ProcessName, mainWindowTitle),
|
||||||
AutoCompleteText = $"{_context.CurrentPluginMetadata.ActionKeyword}{Plugin.Query.TermSeparator}{p.ProcessName}",
|
AutoCompleteText = $"{_context.CurrentPluginMetadata.ActionKeyword}{Plugin.Query.TermSeparator}{p.ProcessName}",
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
|
|
@ -98,14 +108,13 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
}
|
}
|
||||||
|
|
||||||
var sortedResults = results
|
var sortedResults = results
|
||||||
.OrderBy(x => string.IsNullOrEmpty(((RunningProcessInfo)x.ContextData).MainWindowTitle))
|
.OrderBy(x => x.Title)
|
||||||
.ThenBy(x => x.Title)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// When there are multiple results AND all of them are instances of the same executable
|
// 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.
|
// add a quick option to kill them all at the top of the results.
|
||||||
var firstResult = sortedResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.SubTitle));
|
var firstResult = sortedResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.SubTitle));
|
||||||
if (processList.Count > 1 && !string.IsNullOrEmpty(termToSearch) && sortedResults.All(r => r.SubTitle == firstResult?.SubTitle))
|
if (processList.Count > 1 && !string.IsNullOrEmpty(searchTerm) && sortedResults.All(r => r.SubTitle == firstResult?.SubTitle))
|
||||||
{
|
{
|
||||||
sortedResults.Insert(1, new Result()
|
sortedResults.Insert(1, new Result()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a ProcessResult for evey running non-system process whose name matches the given searchTerm
|
/// Returns a ProcessResult for evey running non-system process whose name matches the given searchTerm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ProcessResult> GetMatchingProcesses(string searchTerm)
|
public List<ProcessResult> GetMatchingProcesses(string searchTerm, Dictionary<int, string> processWindowTitle)
|
||||||
{
|
{
|
||||||
var processlist = new List<ProcessResult>();
|
var processlist = new List<ProcessResult>();
|
||||||
|
|
||||||
|
|
@ -49,15 +49,27 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(searchTerm))
|
if (string.IsNullOrWhiteSpace(searchTerm))
|
||||||
{
|
{
|
||||||
// show all non-system processes
|
// Show all non-system processes
|
||||||
processlist.Add(new ProcessResult(p, 0));
|
processlist.Add(new ProcessResult(p, 0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var score = StringMatcher.FuzzySearch(searchTerm, p.ProcessName + p.Id).Score;
|
// Search window title first
|
||||||
if (score > 0)
|
if (processWindowTitle.TryGetValue(p.Id, out var windowTitle))
|
||||||
{
|
{
|
||||||
processlist.Add(new ProcessResult(p, score));
|
var score = StringMatcher.FuzzySearch(searchTerm, windowTitle).Score;
|
||||||
|
if (score > 0)
|
||||||
|
{
|
||||||
|
processlist.Add(new ProcessResult(p, score));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search process name and process id
|
||||||
|
var score1 = StringMatcher.FuzzySearch(searchTerm, p.ProcessName + " - " + p.Id).Score;
|
||||||
|
if (score1 > 0)
|
||||||
|
{
|
||||||
|
processlist.Add(new ProcessResult(p, score1));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue