8
8
using WindowsInput ;
9
9
using WindowsInput . Native ;
10
10
using Flow . Launcher . Infrastructure . Hotkey ;
11
- using Flow . Launcher . Infrastructure . Logger ;
12
11
using Flow . Launcher . Plugin . SharedCommands ;
13
12
using Control = System . Windows . Controls . Control ;
14
13
using Keys = System . Windows . Forms . Keys ;
@@ -17,8 +16,11 @@ namespace Flow.Launcher.Plugin.Shell
17
16
{
18
17
public class Main : IPlugin , ISettingProvider , IPluginI18n , IContextMenu
19
18
{
19
+ private static readonly string ClassName = nameof ( Main ) ;
20
+
21
+ internal PluginInitContext Context { get ; private set ; }
22
+
20
23
private const string Image = "Images/shell.png" ;
21
- private PluginInitContext context ;
22
24
private bool _winRStroked ;
23
25
private readonly KeyboardSimulator _keyboardSimulator = new KeyboardSimulator ( new InputSimulator ( ) ) ;
24
26
@@ -88,7 +90,7 @@ public List<Result> Query(Query query)
88
90
}
89
91
catch ( Exception e )
90
92
{
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 ) ;
92
94
}
93
95
return results ;
94
96
}
@@ -102,14 +104,14 @@ private List<Result> GetHistoryCmds(string cmd, Result result)
102
104
{
103
105
if ( m . Key == cmd )
104
106
{
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 ) ;
106
108
return null ;
107
109
}
108
110
109
111
var ret = new Result
110
112
{
111
113
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 ) ,
113
115
IcoPath = Image ,
114
116
Action = c =>
115
117
{
@@ -139,7 +141,7 @@ private Result GetCurrentCmd(string cmd)
139
141
{
140
142
Title = cmd ,
141
143
Score = 5000 ,
142
- SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_cmd_execute_through_shell" ) ,
144
+ SubTitle = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_execute_through_shell" ) ,
143
145
IcoPath = Image ,
144
146
Action = c =>
145
147
{
@@ -164,7 +166,7 @@ private List<Result> ResultsFromHistory()
164
166
. Select ( m => new Result
165
167
{
166
168
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 ) ,
168
170
IcoPath = Image ,
169
171
Action = c =>
170
172
{
@@ -211,7 +213,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
211
213
info . FileName = "cmd.exe" ;
212
214
}
213
215
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" : "" ) } ") ;
215
217
break ;
216
218
}
217
219
@@ -234,7 +236,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
234
236
else
235
237
{
236
238
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" : "" ) } ") ;
238
240
}
239
241
break ;
240
242
}
@@ -255,7 +257,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
255
257
info . ArgumentList . Add ( "-NoExit" ) ;
256
258
}
257
259
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" : "" ) } ") ;
259
261
break ;
260
262
}
261
263
@@ -309,13 +311,13 @@ private void Execute(Func<ProcessStartInfo, Process> startProcess, ProcessStartI
309
311
{
310
312
var name = "Plugin: Shell" ;
311
313
var message = $ "Command not found: { e . Message } ";
312
- context . API . ShowMsg ( name , message ) ;
314
+ Context . API . ShowMsg ( name , message ) ;
313
315
}
314
316
catch ( Win32Exception e )
315
317
{
316
318
var name = "Plugin: Shell" ;
317
319
var message = $ "Error running the command: { e . Message } ";
318
- context . API . ShowMsg ( name , message ) ;
320
+ Context . API . ShowMsg ( name , message ) ;
319
321
}
320
322
}
321
323
@@ -350,14 +352,14 @@ private bool ExistInPath(string filename)
350
352
351
353
public void Init ( PluginInitContext context )
352
354
{
353
- this . context = context ;
355
+ Context = context ;
354
356
_settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
355
357
context . API . RegisterGlobalKeyboardCallback ( API_GlobalKeyboardEvent ) ;
356
358
}
357
359
358
360
bool API_GlobalKeyboardEvent ( int keyevent , int vkcode , SpecialKeyState state )
359
361
{
360
- if ( ! context . CurrentPluginMetadata . Disabled && _settings . ReplaceWinR )
362
+ if ( ! Context . CurrentPluginMetadata . Disabled && _settings . ReplaceWinR )
361
363
{
362
364
if ( keyevent == ( int ) KeyEvent . WM_KEYDOWN && vkcode == ( int ) Keys . R && state . WinPressed )
363
365
{
@@ -380,10 +382,9 @@ private void OnWinRPressed()
380
382
// show the main window and set focus to the query box
381
383
_ = Task . Run ( ( ) =>
382
384
{
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 } ") ;
385
387
} ) ;
386
-
387
388
}
388
389
389
390
public Control CreateSettingPanel ( )
@@ -393,12 +394,12 @@ public Control CreateSettingPanel()
393
394
394
395
public string GetTranslatedPluginTitle ( )
395
396
{
396
- return context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_name" ) ;
397
+ return Context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_name" ) ;
397
398
}
398
399
399
400
public string GetTranslatedPluginDescription ( )
400
401
{
401
- return context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_description" ) ;
402
+ return Context . API . GetTranslation ( "flowlauncher_plugin_cmd_plugin_description" ) ;
402
403
}
403
404
404
405
public List < Result > LoadContextMenus ( Result selectedResult )
@@ -407,8 +408,8 @@ public List<Result> LoadContextMenus(Result selectedResult)
407
408
{
408
409
new ( )
409
410
{
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 =>
412
413
{
413
414
Execute ( ShellCommand . RunAsDifferentUser , PrepareProcessStartInfo ( selectedResult . Title ) ) ;
414
415
return true ;
@@ -418,7 +419,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
418
419
} ,
419
420
new ( )
420
421
{
421
- Title = context . API . GetTranslation ( "flowlauncher_plugin_cmd_run_as_administrator" ) ,
422
+ Title = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_run_as_administrator" ) ,
422
423
Action = c =>
423
424
{
424
425
Execute ( Process . Start , PrepareProcessStartInfo ( selectedResult . Title , true ) ) ;
@@ -429,10 +430,10 @@ public List<Result> LoadContextMenus(Result selectedResult)
429
430
} ,
430
431
new ( )
431
432
{
432
- Title = context . API . GetTranslation ( "flowlauncher_plugin_cmd_copy" ) ,
433
+ Title = Context . API . GetTranslation ( "flowlauncher_plugin_cmd_copy" ) ,
433
434
Action = c =>
434
435
{
435
- context . API . CopyToClipboard ( selectedResult . Title ) ;
436
+ Context . API . CopyToClipboard ( selectedResult . Title ) ;
436
437
return true ;
437
438
} ,
438
439
IcoPath = "Images/copy.png" ,
0 commit comments