Skip to content

Commit 1e45894

Browse files
Merge pull request #2468 from flooxo/sys_cmd
Add translation keys for System Command Plugin
2 parents 097bc69 + 82a8d56 commit 1e45894

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77
<system:String x:Key="flowlauncher_plugin_sys_command">Command</system:String>
88
<system:String x:Key="flowlauncher_plugin_sys_desc">Description</system:String>
99

10+
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer_cmd">Shutdown</system:String>
11+
<system:String x:Key="flowlauncher_plugin_sys_restart_computer_cmd">Restart</system:String>
12+
<system:String x:Key="flowlauncher_plugin_sys_restart_advanced_cmd">Restart With Advanced Boot Options</system:String>
13+
<system:String x:Key="flowlauncher_plugin_sys_log_off_cmd">Log Off/Sign Out</system:String>
14+
<system:String x:Key="flowlauncher_plugin_sys_lock_cmd">Lock</system:String>
15+
<system:String x:Key="flowlauncher_plugin_sys_sleep_cmd">Sleep</system:String>
16+
<system:String x:Key="flowlauncher_plugin_sys_hibernate_cmd">Hibernate</system:String>
17+
<system:String x:Key="flowlauncher_plugin_sys_indexoption_cmd">Index Option</system:String>
18+
<system:String x:Key="flowlauncher_plugin_sys_emptyrecyclebin_cmd">Empty Recycle Bin</system:String>
19+
<system:String x:Key="flowlauncher_plugin_sys_openrecyclebin_cmd">Open Recycle Bin</system:String>
20+
<system:String x:Key="flowlauncher_plugin_sys_exit_cmd">Exit</system:String>
21+
<system:String x:Key="flowlauncher_plugin_sys_save_all_settings_cmd">Save Settings</system:String>
22+
<system:String x:Key="flowlauncher_plugin_sys_restart_cmd">Restart Flow Launcher"</system:String>
23+
<system:String x:Key="flowlauncher_plugin_sys_setting_cmd">Settings</system:String>
24+
<system:String x:Key="flowlauncher_plugin_sys_reload_plugin_data_cmd">Reload Plugin Data</system:String>
25+
<system:String x:Key="flowlauncher_plugin_sys_check_for_update_cmd">Check For Update</system:String>
26+
<system:String x:Key="flowlauncher_plugin_sys_open_log_location_cmd">Open Log Location</system:String>
27+
<system:String x:Key="flowlauncher_plugin_sys_open_docs_tips_cmd">Flow Launcher Tips</system:String>
28+
<system:String x:Key="flowlauncher_plugin_sys_open_userdata_location_cmd">Flow Launcher UserData Folder</system:String>
29+
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode_cmd">Toggle Game Mode</system:String>
30+
31+
<!-- Command Descriptions -->
1032
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer">Shutdown Computer</system:String>
1133
<system:String x:Key="flowlauncher_plugin_sys_restart_computer">Restart Computer</system:String>
1234
<system:String x:Key="flowlauncher_plugin_sys_restart_advanced">Restart the computer with Advanced Boot Options for Safe and Debugging modes, as well as other options</system:String>

Plugins/Flow.Launcher.Plugin.Sys/Main.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Windows;
78
using System.Windows.Forms;
89
using System.Windows.Interop;
910
using Flow.Launcher.Infrastructure;
11+
using Flow.Launcher.Infrastructure.Logger;
1012
using Flow.Launcher.Infrastructure.UserSettings;
1113
using Flow.Launcher.Plugin.SharedCommands;
1214
using Application = System.Windows.Application;
@@ -19,6 +21,7 @@ namespace Flow.Launcher.Plugin.Sys
1921
public class Main : IPlugin, ISettingProvider, IPluginI18n
2022
{
2123
private PluginInitContext context;
24+
private Dictionary<string, string> KeywordTitleMappings = new Dictionary<string, string>();
2225

2326
#region DllImport
2427

@@ -59,6 +62,8 @@ public List<Result> Query(Query query)
5962
var results = new List<Result>();
6063
foreach (var c in commands)
6164
{
65+
c.Title = GetDynamicTitle(query, c);
66+
6267
var titleMatch = StringMatcher.FuzzySearch(query.Search, c.Title);
6368
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, c.SubTitle);
6469

@@ -77,9 +82,52 @@ public List<Result> Query(Query query)
7782
return results;
7883
}
7984

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+
80106
public void Init(PluginInitContext context)
81107
{
82108
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+
};
83131
}
84132

85133
private List<Result> Commands()
@@ -139,7 +187,7 @@ private List<Result> Commands()
139187
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
140188
context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
141189
MessageBoxButton.YesNo, MessageBoxImage.Warning);
142-
190+
143191
if (result == MessageBoxResult.Yes)
144192
Process.Start("shutdown", "/r /o /t 0");
145193

@@ -158,7 +206,7 @@ private List<Result> Commands()
158206
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"),
159207
context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
160208
MessageBoxButton.YesNo, MessageBoxImage.Warning);
161-
209+
162210
if (result == MessageBoxResult.Yes)
163211
ExitWindowsEx(EWX_LOGOFF, 0);
164212

@@ -198,7 +246,7 @@ private List<Result> Commands()
198246
info.UseShellExecute = true;
199247

200248
ShellCommand.Execute(info);
201-
249+
202250
return true;
203251
}
204252
},
@@ -317,7 +365,7 @@ private List<Result> Commands()
317365
context.API.GetTranslation(
318366
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")),
319367
System.Threading.Tasks.TaskScheduler.Current);
320-
368+
321369
return true;
322370
}
323371
},

0 commit comments

Comments
 (0)