88using WindowsInput ;
99using WindowsInput . Native ;
1010using Flow . Launcher . Infrastructure . Hotkey ;
11- using Flow . Launcher . Infrastructure . Logger ;
1211using Flow . Launcher . Plugin . SharedCommands ;
1312using Control = System . Windows . Controls . Control ;
1413using Keys = System . Windows . Forms . Keys ;
@@ -17,8 +16,11 @@ namespace Flow.Launcher.Plugin.Shell
1716{
1817 public class Main : IPlugin , ISettingProvider , IPluginI18n , IContextMenu
1918 {
19+ private static readonly string ClassName = nameof ( Main ) ;
20+
21+ internal PluginInitContext Context { get ; private set ; }
22+
2023 private const string Image = "Images/shell.png" ;
21- private PluginInitContext context ;
2224 private bool _winRStroked ;
2325 private readonly KeyboardSimulator _keyboardSimulator = new KeyboardSimulator ( new InputSimulator ( ) ) ;
2426
@@ -88,7 +90,7 @@ public List<Result> Query(Query query)
8890 }
8991 catch ( Exception e )
9092 {
91- Log . Exception ( $ "|Flow.Launcher.Plugin.Shell.Main.Query| Exception when query for <{ query } >", e ) ;
93+ Context . API . LogException ( ClassName , $ " Exception when query for <{ query } >", e ) ;
9294 }
9395 return results ;
9496 }
@@ -102,14 +104,14 @@ private List<Result> GetHistoryCmds(string cmd, Result result)
102104 {
103105 if ( m . Key == cmd )
104106 {
105- result . SubTitle = string . Format ( context . API . GetTranslation ( "flowlauncher_plugin_cmd_cmd_has_been_executed_times" ) , m . Value ) ;
107+ result . SubTitle = string . Format ( Context . API . GetTranslation ( "flowlauncher_plugin_cmd_cmd_has_been_executed_times" ) , m . Value ) ;
106108 return null ;
107109 }
108110
109111 var ret = new Result
110112 {
111113 Title = m . Key ,
112- SubTitle = string . Format ( context . API . GetTranslation ( "flowlauncher_plugin_cmd_cmd_has_been_executed_times" ) , m . Value ) ,
114+ SubTitle = string . Format ( Context . API . GetTranslation ( "flowlauncher_plugin_cmd_cmd_has_been_executed_times" ) , m . Value ) ,
113115 IcoPath = Image ,
114116 Action = c =>
115117 {
@@ -139,7 +141,7 @@ private Result GetCurrentCmd(string cmd)
139141 {
140142 Title = cmd ,
141143 Score = 5000 ,
142- SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_cmd_execute_through_shell" ) ,
144+ SubTitle = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_execute_through_shell" ) ,
143145 IcoPath = Image ,
144146 Action = c =>
145147 {
@@ -164,7 +166,7 @@ private List<Result> ResultsFromHistory()
164166 . Select ( m => new Result
165167 {
166168 Title = m . Key ,
167- SubTitle = string . Format ( context . API . GetTranslation ( "flowlauncher_plugin_cmd_cmd_has_been_executed_times" ) , m . Value ) ,
169+ SubTitle = string . Format ( Context . API . GetTranslation ( "flowlauncher_plugin_cmd_cmd_has_been_executed_times" ) , m . Value ) ,
168170 IcoPath = Image ,
169171 Action = c =>
170172 {
@@ -211,7 +213,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
211213 info . FileName = "cmd.exe" ;
212214 }
213215
214- info . ArgumentList . Add ( $ "{ ( _settings . LeaveShellOpen ? "/k" : "/c" ) } { command } { ( _settings . CloseShellAfterPress ? $ "&& echo { context . API . GetTranslation ( "flowlauncher_plugin_cmd_press_any_key_to_close" ) } && pause > nul /c" : "" ) } ") ;
216+ info . ArgumentList . Add ( $ "{ ( _settings . LeaveShellOpen ? "/k" : "/c" ) } { command } { ( _settings . CloseShellAfterPress ? $ "&& echo { Context . API . GetTranslation ( "flowlauncher_plugin_cmd_press_any_key_to_close" ) } && pause > nul /c" : "" ) } ") ;
215217 break ;
216218 }
217219
@@ -234,7 +236,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
234236 else
235237 {
236238 info . ArgumentList . Add ( "-Command" ) ;
237- info . ArgumentList . Add ( $ "{ command } \\ ; { ( _settings . CloseShellAfterPress ? $ "Write-Host '{ context . API . GetTranslation ( "flowlauncher_plugin_cmd_press_any_key_to_close" ) } '\\ ; [System.Console]::ReadKey()\\ ; exit" : "" ) } ") ;
239+ info . ArgumentList . Add ( $ "{ command } \\ ; { ( _settings . CloseShellAfterPress ? $ "Write-Host '{ Context . API . GetTranslation ( "flowlauncher_plugin_cmd_press_any_key_to_close" ) } '\\ ; [System.Console]::ReadKey()\\ ; exit" : "" ) } ") ;
238240 }
239241 break ;
240242 }
@@ -255,7 +257,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
255257 info . ArgumentList . Add ( "-NoExit" ) ;
256258 }
257259 info . ArgumentList . Add ( "-Command" ) ;
258- info . ArgumentList . Add ( $ "{ command } \\ ; { ( _settings . CloseShellAfterPress ? $ "Write-Host '{ context . API . GetTranslation ( "flowlauncher_plugin_cmd_press_any_key_to_close" ) } '\\ ; [System.Console]::ReadKey()\\ ; exit" : "" ) } ") ;
260+ info . ArgumentList . Add ( $ "{ command } \\ ; { ( _settings . CloseShellAfterPress ? $ "Write-Host '{ Context . API . GetTranslation ( "flowlauncher_plugin_cmd_press_any_key_to_close" ) } '\\ ; [System.Console]::ReadKey()\\ ; exit" : "" ) } ") ;
259261 break ;
260262 }
261263
@@ -309,13 +311,13 @@ private void Execute(Func<ProcessStartInfo, Process> startProcess, ProcessStartI
309311 {
310312 var name = "Plugin: Shell" ;
311313 var message = $ "Command not found: { e . Message } ";
312- context . API . ShowMsg ( name , message ) ;
314+ Context . API . ShowMsg ( name , message ) ;
313315 }
314316 catch ( Win32Exception e )
315317 {
316318 var name = "Plugin: Shell" ;
317319 var message = $ "Error running the command: { e . Message } ";
318- context . API . ShowMsg ( name , message ) ;
320+ Context . API . ShowMsg ( name , message ) ;
319321 }
320322 }
321323
@@ -350,14 +352,14 @@ private bool ExistInPath(string filename)
350352
351353 public void Init ( PluginInitContext context )
352354 {
353- this . context = context ;
355+ Context = context ;
354356 _settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
355357 context . API . RegisterGlobalKeyboardCallback ( API_GlobalKeyboardEvent ) ;
356358 }
357359
358360 bool API_GlobalKeyboardEvent ( int keyevent , int vkcode , SpecialKeyState state )
359361 {
360- if ( ! context . CurrentPluginMetadata . Disabled && _settings . ReplaceWinR )
362+ if ( ! Context . CurrentPluginMetadata . Disabled && _settings . ReplaceWinR )
361363 {
362364 if ( keyevent == ( int ) KeyEvent . WM_KEYDOWN && vkcode == ( int ) Keys . R && state . WinPressed )
363365 {
@@ -380,10 +382,9 @@ private void OnWinRPressed()
380382 // show the main window and set focus to the query box
381383 _ = Task . Run ( ( ) =>
382384 {
383- context . API . ShowMainWindow ( ) ;
384- context . API . ChangeQuery ( $ "{ context . CurrentPluginMetadata . ActionKeywords [ 0 ] } { Plugin . Query . TermSeparator } ") ;
385+ Context . API . ShowMainWindow ( ) ;
386+ Context . API . ChangeQuery ( $ "{ Context . CurrentPluginMetadata . ActionKeywords [ 0 ] } { Plugin . Query . TermSeparator } ") ;
385387 } ) ;
386-
387388 }
388389
389390 public Control CreateSettingPanel ( )
@@ -393,12 +394,12 @@ public Control CreateSettingPanel()
393394
394395 public string GetTranslatedPluginTitle ( )
395396 {
396- return context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_name" ) ;
397+ return Context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_name" ) ;
397398 }
398399
399400 public string GetTranslatedPluginDescription ( )
400401 {
401- return context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_description" ) ;
402+ return Context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_description" ) ;
402403 }
403404
404405 public List < Result > LoadContextMenus ( Result selectedResult )
@@ -407,8 +408,8 @@ public List<Result> LoadContextMenus(Result selectedResult)
407408 {
408409 new ( )
409410 {
410- Title = context . API . GetTranslation ( "flowlauncher_plugin_cmd_run_as_different_user" ) ,
411- AsyncAction = async c =>
411+ Title = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_run_as_different_user" ) ,
412+ Action = c =>
412413 {
413414 Execute ( ShellCommand . RunAsDifferentUser , PrepareProcessStartInfo ( selectedResult . Title ) ) ;
414415 return true ;
@@ -418,7 +419,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
418419 } ,
419420 new ( )
420421 {
421- Title = context . API . GetTranslation ( "flowlauncher_plugin_cmd_run_as_administrator" ) ,
422+ Title = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_run_as_administrator" ) ,
422423 Action = c =>
423424 {
424425 Execute ( Process . Start , PrepareProcessStartInfo ( selectedResult . Title , true ) ) ;
@@ -429,10 +430,10 @@ public List<Result> LoadContextMenus(Result selectedResult)
429430 } ,
430431 new ( )
431432 {
432- Title = context . API . GetTranslation ( "flowlauncher_plugin_cmd_copy" ) ,
433+ Title = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_copy" ) ,
433434 Action = c =>
434435 {
435- context . API . CopyToClipboard ( selectedResult . Title ) ;
436+ Context . API . CopyToClipboard ( selectedResult . Title ) ;
436437 return true ;
437438 } ,
438439 IcoPath = "Images/copy.png" ,
0 commit comments