1
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
2
2
using System . Linq ;
3
3
using Flow . Launcher . Infrastructure ;
4
4
@@ -60,30 +60,33 @@ public List<Result> LoadContextMenus(Result result)
60
60
return menuOptions ;
61
61
}
62
62
63
+ private record RunningProcessInfo ( string ProcessName , string MainWindowTitle ) ;
64
+
63
65
private List < Result > CreateResultsFromQuery ( Query query )
64
66
{
65
67
string termToSearch = query . Search ;
66
- var processlist = processHelper . GetMatchingProcesses ( termToSearch ) ;
67
-
68
- if ( ! processlist . Any ( ) )
68
+ var processList = processHelper . GetMatchingProcesses ( termToSearch ) ;
69
+ var processWithNonEmptyMainWindowTitleList = processHelper . GetProcessesWithNonEmptyWindowTitle ( ) ;
70
+
71
+ if ( ! processList . Any ( ) )
69
72
{
70
73
return null ;
71
74
}
72
75
73
76
var results = new List < Result > ( ) ;
74
77
75
- foreach ( var pr in processlist )
78
+ foreach ( var pr in processList )
76
79
{
77
80
var p = pr . Process ;
78
81
var path = processHelper . TryGetProcessFilename ( p ) ;
79
82
results . Add ( new Result ( )
80
83
{
81
84
IcoPath = path ,
82
- Title = p . ProcessName + " - " + p . Id ,
85
+ Title = processWithNonEmptyMainWindowTitleList . TryGetValue ( p . Id , out var mainWindowTitle ) ? mainWindowTitle : p . ProcessName + " - " + p . Id ,
83
86
SubTitle = path ,
84
87
TitleHighlightData = StringMatcher . FuzzySearch ( termToSearch , p . ProcessName ) . MatchData ,
85
88
Score = pr . Score ,
86
- ContextData = p . ProcessName ,
89
+ ContextData = new RunningProcessInfo ( p . ProcessName , mainWindowTitle ) ,
87
90
AutoCompleteText = $ "{ _context . CurrentPluginMetadata . ActionKeyword } { Plugin . Query . TermSeparator } { p . ProcessName } ",
88
91
Action = ( c ) =>
89
92
{
@@ -95,22 +98,25 @@ private List<Result> CreateResultsFromQuery(Query query)
95
98
} ) ;
96
99
}
97
100
98
- var sortedResults = results . OrderBy ( x => x . Title ) . ToList ( ) ;
101
+ var sortedResults = results
102
+ . OrderBy ( x => string . IsNullOrEmpty ( ( ( RunningProcessInfo ) x . ContextData ) . MainWindowTitle ) )
103
+ . ThenBy ( x => x . Title )
104
+ . ToList ( ) ;
99
105
100
106
// When there are multiple results AND all of them are instances of the same executable
101
107
// add a quick option to kill them all at the top of the results.
102
108
var firstResult = sortedResults . FirstOrDefault ( x => ! string . IsNullOrEmpty ( x . SubTitle ) ) ;
103
- if ( processlist . Count > 1 && ! string . IsNullOrEmpty ( termToSearch ) && sortedResults . All ( r => r . SubTitle == firstResult ? . SubTitle ) )
109
+ if ( processList . Count > 1 && ! string . IsNullOrEmpty ( termToSearch ) && sortedResults . All ( r => r . SubTitle == firstResult ? . SubTitle ) )
104
110
{
105
111
sortedResults . Insert ( 1 , new Result ( )
106
112
{
107
113
IcoPath = firstResult ? . IcoPath ,
108
- Title = string . Format ( _context . API . GetTranslation ( "flowlauncher_plugin_processkiller_kill_all" ) , firstResult ? . ContextData ) ,
109
- SubTitle = string . Format ( _context . API . GetTranslation ( "flowlauncher_plugin_processkiller_kill_all_count" ) , processlist . Count ) ,
114
+ Title = string . Format ( _context . API . GetTranslation ( "flowlauncher_plugin_processkiller_kill_all" ) , ( ( RunningProcessInfo ) firstResult ? . ContextData ) . ProcessName ) ,
115
+ SubTitle = string . Format ( _context . API . GetTranslation ( "flowlauncher_plugin_processkiller_kill_all_count" ) , processList . Count ) ,
110
116
Score = 200 ,
111
117
Action = ( c ) =>
112
118
{
113
- foreach ( var p in processlist )
119
+ foreach ( var p in processList )
114
120
{
115
121
processHelper . TryKill ( p . Process ) ;
116
122
}
0 commit comments