@@ -9,19 +9,19 @@ namespace Flow.Launcher.Plugin.ProcessKiller
99{
1010 public class Main : IPlugin , IPluginI18n , IContextMenu , ISettingProvider
1111 {
12- private readonly ProcessHelper processHelper = new ( ) ;
12+ internal static PluginInitContext Context { get ; private set ; }
1313
14- private static PluginInitContext _context ;
14+ private Settings _settings ;
1515
16- internal Settings Settings ;
16+ private readonly ProcessHelper processHelper = new ( ) ;
1717
1818 private SettingsViewModel _viewModel ;
1919
2020 public void Init ( PluginInitContext context )
2121 {
22- _context = context ;
23- Settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
24- _viewModel = new SettingsViewModel ( Settings ) ;
22+ Context = context ;
23+ _settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
24+ _viewModel = new SettingsViewModel ( _settings ) ;
2525 }
2626
2727 public List < Result > Query ( Query query )
@@ -31,12 +31,12 @@ public List<Result> Query(Query query)
3131
3232 public string GetTranslatedPluginTitle ( )
3333 {
34- return _context . API . GetTranslation ( " flowlauncher_plugin_processkiller_plugin_name" ) ;
34+ return Localize . flowlauncher_plugin_processkiller_plugin_name ( ) ;
3535 }
3636
3737 public string GetTranslatedPluginDescription ( )
3838 {
39- return _context . API . GetTranslation ( " flowlauncher_plugin_processkiller_plugin_description" ) ;
39+ return Localize . flowlauncher_plugin_processkiller_plugin_description ( ) ;
4040 }
4141
4242 public List < Result > LoadContextMenus ( Result result )
@@ -51,13 +51,13 @@ public List<Result> LoadContextMenus(Result result)
5151 {
5252 menuOptions . Add ( new Result
5353 {
54- Title = _context . API . GetTranslation ( " flowlauncher_plugin_processkiller_kill_instances" ) ,
54+ Title = Localize . flowlauncher_plugin_processkiller_kill_instances ( ) ,
5555 SubTitle = processPath ,
5656 Action = _ =>
5757 {
5858 foreach ( var p in similarProcesses )
5959 {
60- processHelper . TryKill ( _context , p ) ;
60+ ProcessHelper . TryKill ( p ) ;
6161 }
6262
6363 return true ;
@@ -72,8 +72,8 @@ public List<Result> LoadContextMenus(Result result)
7272 private List < Result > CreateResultsFromQuery ( Query query )
7373 {
7474 // Get all non-system processes
75- var allPocessList = processHelper . GetMatchingProcesses ( ) ;
76- if ( ! allPocessList . Any ( ) )
75+ var allProcessList = processHelper . GetMatchingProcesses ( ) ;
76+ if ( allProcessList . Count == 0 )
7777 {
7878 return null ;
7979 }
@@ -82,12 +82,12 @@ private List<Result> CreateResultsFromQuery(Query query)
8282 var searchTerm = query . Search ;
8383 var processlist = new List < ProcessResult > ( ) ;
8484 var processWindowTitle =
85- Settings . ShowWindowTitle || Settings . PutVisibleWindowProcessesTop ?
85+ _settings . ShowWindowTitle || _settings . PutVisibleWindowProcessesTop ?
8686 ProcessHelper . GetProcessesWithNonEmptyWindowTitle ( ) :
87- new Dictionary < int , string > ( ) ;
87+ [ ] ;
8888 if ( string . IsNullOrWhiteSpace ( searchTerm ) )
8989 {
90- foreach ( var p in allPocessList )
90+ foreach ( var p in allProcessList )
9191 {
9292 var progressNameIdTitle = ProcessHelper . GetProcessNameIdTitle ( p ) ;
9393
@@ -97,8 +97,8 @@ private List<Result> CreateResultsFromQuery(Query query)
9797 // Use window title for those processes if enabled
9898 processlist . Add ( new ProcessResult (
9999 p ,
100- Settings . PutVisibleWindowProcessesTop ? 200 : 0 ,
101- Settings . ShowWindowTitle ? windowTitle : progressNameIdTitle ,
100+ _settings . PutVisibleWindowProcessesTop ? 200 : 0 ,
101+ _settings . ShowWindowTitle ? windowTitle : progressNameIdTitle ,
102102 null ,
103103 progressNameIdTitle ) ) ;
104104 }
@@ -115,35 +115,35 @@ private List<Result> CreateResultsFromQuery(Query query)
115115 }
116116 else
117117 {
118- foreach ( var p in allPocessList )
118+ foreach ( var p in allProcessList )
119119 {
120120 var progressNameIdTitle = ProcessHelper . GetProcessNameIdTitle ( p ) ;
121121
122122 if ( processWindowTitle . TryGetValue ( p . Id , out var windowTitle ) )
123123 {
124124 // Get max score from searching process name, window title and process id
125- var windowTitleMatch = _context . API . FuzzySearch ( searchTerm , windowTitle ) ;
126- var processNameIdMatch = _context . API . FuzzySearch ( searchTerm , progressNameIdTitle ) ;
125+ var windowTitleMatch = Context . API . FuzzySearch ( searchTerm , windowTitle ) ;
126+ var processNameIdMatch = Context . API . FuzzySearch ( searchTerm , progressNameIdTitle ) ;
127127 var score = Math . Max ( windowTitleMatch . Score , processNameIdMatch . Score ) ;
128128 if ( score > 0 )
129129 {
130130 // Add score to prioritize processes with visible windows
131131 // Use window title for those processes
132- if ( Settings . PutVisibleWindowProcessesTop )
132+ if ( _settings . PutVisibleWindowProcessesTop )
133133 {
134134 score += 200 ;
135135 }
136136 processlist . Add ( new ProcessResult (
137137 p ,
138138 score ,
139- Settings . ShowWindowTitle ? windowTitle : progressNameIdTitle ,
139+ _settings . ShowWindowTitle ? windowTitle : progressNameIdTitle ,
140140 score == windowTitleMatch . Score ? windowTitleMatch : null ,
141141 progressNameIdTitle ) ) ;
142142 }
143143 }
144144 else
145145 {
146- var processNameIdMatch = _context . API . FuzzySearch ( searchTerm , progressNameIdTitle ) ;
146+ var processNameIdMatch = Context . API . FuzzySearch ( searchTerm , progressNameIdTitle ) ;
147147 var score = processNameIdMatch . Score ;
148148 if ( score > 0 )
149149 {
@@ -162,7 +162,7 @@ private List<Result> CreateResultsFromQuery(Query query)
162162 foreach ( var pr in processlist )
163163 {
164164 var p = pr . Process ;
165- var path = processHelper . TryGetProcessFilename ( p ) ;
165+ var path = ProcessHelper . TryGetProcessFilename ( p ) ;
166166 results . Add ( new Result ( )
167167 {
168168 IcoPath = path ,
@@ -172,12 +172,12 @@ private List<Result> CreateResultsFromQuery(Query query)
172172 TitleHighlightData = pr . TitleMatch ? . MatchData ,
173173 Score = pr . Score ,
174174 ContextData = p . ProcessName ,
175- AutoCompleteText = $ "{ _context . CurrentPluginMetadata . ActionKeyword } { Plugin . Query . TermSeparator } { p . ProcessName } ",
175+ AutoCompleteText = $ "{ Context . CurrentPluginMetadata . ActionKeyword } { Plugin . Query . TermSeparator } { p . ProcessName } ",
176176 Action = ( c ) =>
177177 {
178- processHelper . TryKill ( _context , p ) ;
178+ ProcessHelper . TryKill ( p ) ;
179179 // Re-query to refresh process list
180- _context . API . ReQuery ( ) ;
180+ Context . API . ReQuery ( ) ;
181181 return true ;
182182 }
183183 } ) ;
@@ -194,17 +194,17 @@ private List<Result> CreateResultsFromQuery(Query query)
194194 sortedResults . Insert ( 1 , new Result ( )
195195 {
196196 IcoPath = firstResult ? . IcoPath ,
197- Title = string . Format ( _context . API . GetTranslation ( " flowlauncher_plugin_processkiller_kill_all" ) , firstResult ? . ContextData ) ,
198- SubTitle = string . Format ( _context . API . GetTranslation ( " flowlauncher_plugin_processkiller_kill_all_count" ) , processlist . Count ) ,
197+ Title = Localize . flowlauncher_plugin_processkiller_kill_all ( firstResult ? . ContextData ) ,
198+ SubTitle = Localize . flowlauncher_plugin_processkiller_kill_all_count ( processlist . Count ) ,
199199 Score = 200 ,
200200 Action = ( c ) =>
201201 {
202202 foreach ( var p in processlist )
203203 {
204- processHelper . TryKill ( _context , p . Process ) ;
204+ ProcessHelper . TryKill ( p . Process ) ;
205205 }
206206 // Re-query to refresh process list
207- _context . API . ReQuery ( ) ;
207+ Context . API . ReQuery ( ) ;
208208 return true ;
209209 }
210210 } ) ;
0 commit comments