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,52 @@ public List<Result> Query(Query query)
77
82
return results ;
78
83
}
79
84
85
+ private string GetDynamicTitle ( Query query , Result result )
86
+ {
87
+ if ( ! KeywordTitleMappings . TryGetValue ( result . Title , out var translationKey ) )
88
+ {
89
+ Log . Error ( "Flow.Launcher.Plugin.Sys.Main" , $ "Dynamic Title not found for: { result . Title } ") ;
90
+ return "Title Not Found" ;
91
+ }
92
+
93
+ var translatedTitle = context . API . GetTranslation ( translationKey ) ;
94
+
95
+ if ( result . Title == translatedTitle )
96
+ {
97
+ return result . Title ;
98
+ }
99
+
100
+ var englishTitleMatch = StringMatcher . FuzzySearch ( query . Search , result . Title ) ;
101
+ var translatedTitleMatch = StringMatcher . FuzzySearch ( query . Search , translatedTitle ) ;
102
+
103
+ return englishTitleMatch . Score >= translatedTitleMatch . Score ? result . Title : translatedTitle ;
104
+ }
105
+
80
106
public void Init ( PluginInitContext context )
81
107
{
82
108
this . context = context ;
109
+ KeywordTitleMappings = new Dictionary < string , string > {
110
+ { "Shutdown" , "flowlauncher_plugin_sys_shutdown_computer_cmd" } ,
111
+ { "Restart" , "flowlauncher_plugin_sys_restart_computer_cmd" } ,
112
+ { "Restart With Advanced Boot Options" , "flowlauncher_plugin_sys_restart_advanced_cmd" } ,
113
+ { "Log Off/Sign Out" , "flowlauncher_plugin_sys_log_off_cmd" } ,
114
+ { "Lock" , "flowlauncher_plugin_sys_lock_cmd" } ,
115
+ { "Sleep" , "flowlauncher_plugin_sys_sleep_cmd" } ,
116
+ { "Hibernate" , "flowlauncher_plugin_sys_hibernate_cmd" } ,
117
+ { "Index Option" , "flowlauncher_plugin_sys_indexoption_cmd" } ,
118
+ { "Empty Recycle Bin" , "flowlauncher_plugin_sys_emptyrecyclebin_cmd" } ,
119
+ { "Open Recycle Bin" , "flowlauncher_plugin_sys_openrecyclebin_cmd" } ,
120
+ { "Exit" , "flowlauncher_plugin_sys_exit_cmd" } ,
121
+ { "Save Settings" , "flowlauncher_plugin_sys_save_all_settings_cmd" } ,
122
+ { "Restart Flow Launcher" , "flowlauncher_plugin_sys_restart_cmd" } ,
123
+ { "Settings" , "flowlauncher_plugin_sys_setting_cmd" } ,
124
+ { "Reload Plugin Data" , "flowlauncher_plugin_sys_reload_plugin_data_cmd" } ,
125
+ { "Check For Update" , "flowlauncher_plugin_sys_check_for_update_cmd" } ,
126
+ { "Open Log Location" , "flowlauncher_plugin_sys_open_log_location_cmd" } ,
127
+ { "Flow Launcher Tips" , "flowlauncher_plugin_sys_open_docs_tips_cmd" } ,
128
+ { "Flow Launcher UserData Folder" , "flowlauncher_plugin_sys_open_userdata_location_cmd" } ,
129
+ { "Toggle Game Mode" , "flowlauncher_plugin_sys_toggle_game_mode_cmd" }
130
+ } ;
83
131
}
84
132
85
133
private List < Result > Commands ( )
@@ -139,7 +187,7 @@ private List<Result> Commands()
139
187
context . API . GetTranslation ( "flowlauncher_plugin_sys_dlgtext_restart_computer_advanced" ) ,
140
188
context . API . GetTranslation ( "flowlauncher_plugin_sys_restart_computer" ) ,
141
189
MessageBoxButton . YesNo , MessageBoxImage . Warning ) ;
142
-
190
+
143
191
if ( result == MessageBoxResult . Yes )
144
192
Process . Start ( "shutdown" , "/r /o /t 0" ) ;
145
193
@@ -158,7 +206,7 @@ private List<Result> Commands()
158
206
context . API . GetTranslation ( "flowlauncher_plugin_sys_dlgtext_logoff_computer" ) ,
159
207
context . API . GetTranslation ( "flowlauncher_plugin_sys_log_off" ) ,
160
208
MessageBoxButton . YesNo , MessageBoxImage . Warning ) ;
161
-
209
+
162
210
if ( result == MessageBoxResult . Yes )
163
211
ExitWindowsEx ( EWX_LOGOFF , 0 ) ;
164
212
@@ -198,7 +246,7 @@ private List<Result> Commands()
198
246
info . UseShellExecute = true ;
199
247
200
248
ShellCommand . Execute ( info ) ;
201
-
249
+
202
250
return true ;
203
251
}
204
252
} ,
@@ -317,7 +365,7 @@ private List<Result> Commands()
317
365
context . API . GetTranslation (
318
366
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded" ) ) ,
319
367
System . Threading . Tasks . TaskScheduler . Current ) ;
320
-
368
+
321
369
return true ;
322
370
}
323
371
} ,
0 commit comments