2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
+ using System . Linq ;
5
6
using System . Runtime . InteropServices ;
6
7
using System . Windows ;
7
8
using System . Windows . Forms ;
8
9
using System . Windows . Interop ;
9
10
using Flow . Launcher . Infrastructure ;
11
+ using Flow . Launcher . Infrastructure . Logger ;
10
12
using Flow . Launcher . Infrastructure . UserSettings ;
11
13
using Flow . Launcher . Plugin . SharedCommands ;
12
14
using Application = System . Windows . Application ;
@@ -19,6 +21,7 @@ namespace Flow.Launcher.Plugin.Sys
19
21
public class Main : IPlugin , ISettingProvider , IPluginI18n
20
22
{
21
23
private PluginInitContext context ;
24
+ private Dictionary < string , string > KeywordTitleMappings = new Dictionary < string , string > ( ) ;
22
25
23
26
#region DllImport
24
27
@@ -59,6 +62,8 @@ public List<Result> Query(Query query)
59
62
var results = new List < Result > ( ) ;
60
63
foreach ( var c in commands )
61
64
{
65
+ c . Title = GetDynamicTitle ( query , c ) ;
66
+
62
67
var titleMatch = StringMatcher . FuzzySearch ( query . Search , c . Title ) ;
63
68
var subTitleMatch = StringMatcher . FuzzySearch ( query . Search , c . SubTitle ) ;
64
69
@@ -77,9 +82,48 @@ public List<Result> Query(Query query)
77
82
return results ;
78
83
}
79
84
85
+ private string GetDynamicTitle ( Query query , Result result )
86
+ {
87
+ var pair = KeywordTitleMappings
88
+ . Where ( kvp => kvp . Key == result . Title && kvp . Key != kvp . Value )
89
+ . FirstOrDefault ( ) ;
90
+
91
+ if ( pair . Equals ( default ) )
92
+ {
93
+ Log . Error ( $ "Dynamic Title not found for: { result . Title } ") ;
94
+ return "Title Not Found" ;
95
+ }
96
+
97
+ var englishTitleMatch = StringMatcher . FuzzySearch ( query . Search , pair . Key ) ;
98
+ var translatedTitleMatch = StringMatcher . FuzzySearch ( query . Search , pair . Value ) ;
99
+
100
+ return englishTitleMatch . Score >= translatedTitleMatch . Score ? pair . Key : pair . Value ;
101
+ }
102
+
80
103
public void Init ( PluginInitContext context )
81
104
{
82
105
this . context = context ;
106
+ KeywordTitleMappings = new Dictionary < string , string > {
107
+ { "Shutdown" , context . API . GetTranslation ( "flowlauncher_plugin_sys_shutdown_computer_cmd" ) } ,
108
+ { "Restart" , context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_computer_cmd" ) } ,
109
+ { "Restart With Advanced Boot Options" , context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_advanced_cmd" ) } ,
110
+ { "Log Off/Sign Out" , context . API . GetTranslation ( "flowlauncher_plugin_sys_log_off_cmd" ) } ,
111
+ { "Lock" , context . API . GetTranslation ( "flowlauncher_plugin_sys_lock_cmd" ) } ,
112
+ { "Sleep" , context . API . GetTranslation ( "flowlauncher_plugin_sys_sleep_cmd" ) } ,
113
+ { "Hibernate" , context . API . GetTranslation ( "flowlauncher_plugin_sys_hibernate_cmd" ) } ,
114
+ { "Index Option" , context . API . GetTranslation ( "flowlauncher_plugin_sys_indexoption_cmd" ) } ,
115
+ { "Empty Recycle Bin" , context . API . GetTranslation ( "flowlauncher_plugin_sys_emptyrecyclebin_cmd" ) } ,
116
+ { "Open Recycle Bin" , context . API . GetTranslation ( "flowlauncher_plugin_sys_openrecyclebin_cmd" ) } ,
117
+ { "Exit" , context . API . GetTranslation ( "flowlauncher_plugin_sys_exit_cmd" ) } ,
118
+ { "Save Settings" , context . API . GetTranslation ( "flowlauncher_plugin_sys_save_all_settings_cmd" ) } ,
119
+ { "Restart Flow Launcher" , context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_cmd" ) } ,
120
+ { "Settings" , context . API . GetTranslation ( "flowlauncher_plugin_sys_setting_cmd" ) } ,
121
+ { "Reload Plugin Data" , context . API . GetTranslation ( "flowlauncher_plugin_sys_reload_plugin_data_cmd" ) } ,
122
+ { "Check For Update" , context . API . GetTranslation ( "flowlauncher_plugin_sys_check_for_update_cmd" ) } ,
123
+ { "Open Log Location" , context . API . GetTranslation ( "flowlauncher_plugin_sys_open_log_location_cmd" ) } ,
124
+ { "Flow Launcher Tips" , context . API . GetTranslation ( "flowlauncher_plugin_sys_open_docs_tips_cmd" ) } ,
125
+ { "Flow Launcher UserData Folder" , context . API . GetTranslation ( "flowlauncher_plugin_sys_open_userdata_location_cmd" ) }
126
+ } ;
83
127
}
84
128
85
129
private List < Result > Commands ( )
@@ -89,7 +133,7 @@ private List<Result> Commands()
89
133
{
90
134
new Result
91
135
{
92
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_shutdown_computer_cmd" ) ,
136
+ Title = "Shutdown" ,
93
137
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_shutdown_computer" ) ,
94
138
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe7e8 " ) ,
95
139
IcoPath = "Images\\ shutdown.png" ,
@@ -109,7 +153,7 @@ private List<Result> Commands()
109
153
} ,
110
154
new Result
111
155
{
112
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_computer_cmd" ) ,
156
+ Title = "Restart" ,
113
157
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_computer" ) ,
114
158
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe777 " ) ,
115
159
IcoPath = "Images\\ restart.png" ,
@@ -129,7 +173,7 @@ private List<Result> Commands()
129
173
} ,
130
174
new Result
131
175
{
132
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_advanced_cmd" ) ,
176
+ Title = "Restart With Advanced Boot Options" ,
133
177
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_advanced" ) ,
134
178
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xecc5 " ) ,
135
179
IcoPath = "Images\\ restart_advanced.png" ,
@@ -139,7 +183,7 @@ private List<Result> Commands()
139
183
context . API . GetTranslation ( "flowlauncher_plugin_sys_dlgtext_restart_computer_advanced" ) ,
140
184
context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_computer" ) ,
141
185
MessageBoxButton . YesNo , MessageBoxImage . Warning ) ;
142
-
186
+
143
187
if ( result == MessageBoxResult . Yes )
144
188
Process . Start ( "shutdown" , "/r /o /t 0" ) ;
145
189
@@ -148,7 +192,7 @@ private List<Result> Commands()
148
192
} ,
149
193
new Result
150
194
{
151
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_log_off_cmd" ) ,
195
+ Title = "Log Off/Sign Out" ,
152
196
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_log_off" ) ,
153
197
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe77b " ) ,
154
198
IcoPath = "Images\\ logoff.png" ,
@@ -158,7 +202,7 @@ private List<Result> Commands()
158
202
context . API . GetTranslation ( "flowlauncher_plugin_sys_dlgtext_logoff_computer" ) ,
159
203
context . API . GetTranslation ( "flowlauncher_plugin_sys_log_off" ) ,
160
204
MessageBoxButton . YesNo , MessageBoxImage . Warning ) ;
161
-
205
+
162
206
if ( result == MessageBoxResult . Yes )
163
207
ExitWindowsEx ( EWX_LOGOFF , 0 ) ;
164
208
@@ -167,7 +211,7 @@ private List<Result> Commands()
167
211
} ,
168
212
new Result
169
213
{
170
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_lock_cmd" ) ,
214
+ Title = "Lock" ,
171
215
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_lock" ) ,
172
216
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe72e " ) ,
173
217
IcoPath = "Images\\ lock.png" ,
@@ -179,15 +223,15 @@ private List<Result> Commands()
179
223
} ,
180
224
new Result
181
225
{
182
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_sleep_cmd" ) ,
226
+ Title = "Sleep" ,
183
227
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_sleep" ) ,
184
228
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xec46 " ) ,
185
229
IcoPath = "Images\\ sleep.png" ,
186
230
Action = c => FormsApplication . SetSuspendState ( PowerState . Suspend , false , false )
187
231
} ,
188
232
new Result
189
233
{
190
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_hibernate_cmd" ) ,
234
+ Title = "Hibernate" ,
191
235
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_hibernate" ) ,
192
236
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe945 " ) ,
193
237
IcoPath = "Images\\ hibernate.png" ,
@@ -198,13 +242,13 @@ private List<Result> Commands()
198
242
info . UseShellExecute = true ;
199
243
200
244
ShellCommand . Execute ( info ) ;
201
-
245
+
202
246
return true ;
203
247
}
204
248
} ,
205
249
new Result
206
250
{
207
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_explorer_cmd" ) ,
251
+ Title = "Index Option" ,
208
252
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_indexoption" ) ,
209
253
IcoPath = "Images\\ indexoption.png" ,
210
254
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe773 " ) ,
@@ -219,7 +263,7 @@ private List<Result> Commands()
219
263
} ,
220
264
new Result
221
265
{
222
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_emptyrecyclebin_cmd" ) ,
266
+ Title = "Empty Recycle Bin" ,
223
267
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_emptyrecyclebin" ) ,
224
268
IcoPath = "Images\\ recyclebin.png" ,
225
269
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe74d " ) ,
@@ -242,7 +286,7 @@ private List<Result> Commands()
242
286
} ,
243
287
new Result
244
288
{
245
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_openrecyclebin_cmd" ) ,
289
+ Title = "Open Recycle Bin" ,
246
290
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_openrecyclebin" ) ,
247
291
IcoPath = "Images\\ openrecyclebin.png" ,
248
292
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xe74d " ) ,
@@ -257,7 +301,7 @@ private List<Result> Commands()
257
301
} ,
258
302
new Result
259
303
{
260
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_exit_cmd" ) ,
304
+ Title = "Exit" ,
261
305
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_exit" ) ,
262
306
IcoPath = "Images\\ app.png" ,
263
307
Action = c =>
@@ -268,7 +312,7 @@ private List<Result> Commands()
268
312
} ,
269
313
new Result
270
314
{
271
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_save_all_settings_cmd" ) ,
315
+ Title = "Save Settings" ,
272
316
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_save_all_settings" ) ,
273
317
IcoPath = "Images\\ app.png" ,
274
318
Action = c =>
@@ -281,7 +325,7 @@ private List<Result> Commands()
281
325
} ,
282
326
new Result
283
327
{
284
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_cmd" ) ,
328
+ Title = "Restart Flow Launcher" ,
285
329
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_restart" ) ,
286
330
IcoPath = "Images\\ app.png" ,
287
331
Action = c =>
@@ -292,7 +336,7 @@ private List<Result> Commands()
292
336
} ,
293
337
new Result
294
338
{
295
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_setting_cmd" ) ,
339
+ Title = "Settings" ,
296
340
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_setting" ) ,
297
341
IcoPath = "Images\\ app.png" ,
298
342
Action = c =>
@@ -303,7 +347,7 @@ private List<Result> Commands()
303
347
} ,
304
348
new Result
305
349
{
306
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_reload_plugin_data_cmd" ) ,
350
+ Title = "Reload Plugin Data" ,
307
351
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_reload_plugin_data" ) ,
308
352
IcoPath = "Images\\ app.png" ,
309
353
Action = c =>
@@ -317,13 +361,13 @@ private List<Result> Commands()
317
361
context . API . GetTranslation (
318
362
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded" ) ) ,
319
363
System . Threading . Tasks . TaskScheduler . Current ) ;
320
-
364
+
321
365
return true ;
322
366
}
323
367
} ,
324
368
new Result
325
369
{
326
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_check_for_update_cmd" ) ,
370
+ Title = "Check For Update" ,
327
371
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_check_for_update" ) ,
328
372
IcoPath = "Images\\ checkupdate.png" ,
329
373
Action = c =>
@@ -335,7 +379,7 @@ private List<Result> Commands()
335
379
} ,
336
380
new Result
337
381
{
338
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_open_log_location_cmd" ) ,
382
+ Title = "Open Log Location" ,
339
383
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_open_log_location" ) ,
340
384
IcoPath = "Images\\ app.png" ,
341
385
Action = c =>
@@ -347,7 +391,7 @@ private List<Result> Commands()
347
391
} ,
348
392
new Result
349
393
{
350
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_open_docs_tips_cmd" ) ,
394
+ Title = "Flow Launcher Tips" ,
351
395
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_open_docs_tips" ) ,
352
396
IcoPath = "Images\\ app.png" ,
353
397
Action = c =>
@@ -358,7 +402,7 @@ private List<Result> Commands()
358
402
} ,
359
403
new Result
360
404
{
361
- Title = context . API . GetTranslation ( "flowlauncher_plugin_sys_open_userdata_location_cmd" ) ,
405
+ Title = "Flow Launcher UserData Folder" ,
362
406
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_open_userdata_location" ) ,
363
407
IcoPath = "Images\\ app.png" ,
364
408
Action = c =>
0 commit comments