From 2b8e46611f3259313423fb660418969773e8126e Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Wed, 3 Jan 2024 09:52:12 +0100 Subject: [PATCH 1/7] Add translation keys for sys commands Signed-off-by: Florian Grabmeier --- .../Languages/en.xaml | 21 ++++++++++ Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 38 +++++++++---------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index a9aae930a..7399a55e7 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -7,6 +7,27 @@ Command Description + Shutdown + Restart + Restart With Advanced Boot Options + Log Off + Lock + Sleep + Hibernate + Index Option + Empty Recycle Bin + Open Recycle Bin + Exit + Save Settings + Restart Flow Launcher" + Settings + Reload Plugin Data + Check For Update + Open Log Location + Flow Launcher Tips + Flow Launcher UserData Folder + + Shutdown Computer Restart Computer Restart the computer with Advanced Boot Options for Safe and Debugging modes, as well as other options diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 43f293f74..293fe5869 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -89,7 +89,7 @@ namespace Flow.Launcher.Plugin.Sys { new Result { - Title = "Shutdown", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe7e8"), IcoPath = "Images\\shutdown.png", @@ -109,7 +109,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Restart", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe777"), IcoPath = "Images\\restart.png", @@ -129,7 +129,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Restart With Advanced Boot Options", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xecc5"), IcoPath = "Images\\restart_advanced.png", @@ -148,7 +148,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Log Off", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_log_off_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_log_off"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe77b"), IcoPath = "Images\\logoff.png", @@ -167,7 +167,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Lock", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_lock_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_lock"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe72e"), IcoPath = "Images\\lock.png", @@ -179,7 +179,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Sleep", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_sleep_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_sleep"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xec46"), IcoPath = "Images\\sleep.png", @@ -187,7 +187,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Hibernate", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe945"), IcoPath = "Images\\hibernate.png", @@ -204,7 +204,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Index Option", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_explorer_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_indexoption"), IcoPath = "Images\\indexoption.png", Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe773"), @@ -219,7 +219,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Empty Recycle Bin", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin"), IcoPath = "Images\\recyclebin.png", Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"), @@ -242,7 +242,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Open Recycle Bin", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin"), IcoPath = "Images\\openrecyclebin.png", Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"), @@ -257,7 +257,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Exit", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_exit_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_exit"), IcoPath = "Images\\app.png", Action = c => @@ -268,7 +268,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Save Settings", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings"), IcoPath = "Images\\app.png", Action = c => @@ -281,7 +281,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Restart Flow Launcher", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart"), IcoPath = "Images\\app.png", Action = c => @@ -292,7 +292,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Settings", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_setting_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_setting"), IcoPath = "Images\\app.png", Action = c => @@ -303,7 +303,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Reload Plugin Data", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data"), IcoPath = "Images\\app.png", Action = c => @@ -323,7 +323,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Check For Update", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update"), IcoPath = "Images\\checkupdate.png", Action = c => @@ -335,7 +335,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Open Log Location", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location"), IcoPath = "Images\\app.png", Action = c => @@ -347,7 +347,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Flow Launcher Tips", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips"), IcoPath = "Images\\app.png", Action = c => @@ -358,7 +358,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = "Flow Launcher UserData Folder", + Title = context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location_cmd"), SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location"), IcoPath = "Images\\app.png", Action = c => From 570b2029e625e7edd7bcfa4648e106bbb08d45e6 Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Wed, 3 Jan 2024 10:05:39 +0100 Subject: [PATCH 2/7] Update wrong key translation Signed-off-by: Florian Grabmeier --- Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index 7399a55e7..446290347 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -10,7 +10,7 @@ Shutdown Restart Restart With Advanced Boot Options - Log Off + Log Off/Sign Out Lock Sleep Hibernate From 224dab70a96b75c9de81a47a12b921bced2cb2e3 Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Mon, 15 Jan 2024 16:16:07 +0100 Subject: [PATCH 3/7] Add dynamic title Signed-off-by: Florian Grabmeier --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 90 ++++++++++++++++++------ 1 file changed, 67 insertions(+), 23 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 293fe5869..37ea6b7ea 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Forms; using System.Windows.Interop; using Flow.Launcher.Infrastructure; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin.SharedCommands; using Application = System.Windows.Application; @@ -19,6 +21,7 @@ namespace Flow.Launcher.Plugin.Sys public class Main : IPlugin, ISettingProvider, IPluginI18n { private PluginInitContext context; + private Dictionary KeywordTitleMappings = new Dictionary(); #region DllImport @@ -59,6 +62,8 @@ namespace Flow.Launcher.Plugin.Sys var results = new List(); foreach (var c in commands) { + c.Title = GetDynamicTitle(query, c); + var titleMatch = StringMatcher.FuzzySearch(query.Search, c.Title); var subTitleMatch = StringMatcher.FuzzySearch(query.Search, c.SubTitle); @@ -77,9 +82,48 @@ namespace Flow.Launcher.Plugin.Sys return results; } + private string GetDynamicTitle(Query query, Result result) + { + var pair = KeywordTitleMappings + .Where(kvp => kvp.Key == result.Title && kvp.Key != kvp.Value) + .FirstOrDefault(); + + if (pair.Equals(default)) + { + Log.Error($"Dynamic Title not found for: {result.Title}"); + return "Title Not Found"; + } + + var englishTitleMatch = StringMatcher.FuzzySearch(query.Search, pair.Key); + var translatedTitleMatch = StringMatcher.FuzzySearch(query.Search, pair.Value); + + return englishTitleMatch.Score >= translatedTitleMatch.Score ? pair.Key : pair.Value; + } + public void Init(PluginInitContext context) { this.context = context; + KeywordTitleMappings = new Dictionary{ + {"Shutdown", context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer_cmd")}, + {"Restart", context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer_cmd")}, + {"Restart With Advanced Boot Options", context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced_cmd")}, + {"Log Off/Sign Out", context.API.GetTranslation("flowlauncher_plugin_sys_log_off_cmd")}, + {"Lock", context.API.GetTranslation("flowlauncher_plugin_sys_lock_cmd")}, + {"Sleep", context.API.GetTranslation("flowlauncher_plugin_sys_sleep_cmd")}, + {"Hibernate", context.API.GetTranslation("flowlauncher_plugin_sys_hibernate_cmd")}, + {"Index Option", context.API.GetTranslation("flowlauncher_plugin_sys_indexoption_cmd")}, + {"Empty Recycle Bin", context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin_cmd")}, + {"Open Recycle Bin", context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin_cmd")}, + {"Exit", context.API.GetTranslation("flowlauncher_plugin_sys_exit_cmd")}, + {"Save Settings", context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings_cmd")}, + {"Restart Flow Launcher", context.API.GetTranslation("flowlauncher_plugin_sys_restart_cmd")}, + {"Settings", context.API.GetTranslation("flowlauncher_plugin_sys_setting_cmd")}, + {"Reload Plugin Data", context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data_cmd")}, + {"Check For Update", context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update_cmd")}, + {"Open Log Location", context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location_cmd")}, + {"Flow Launcher Tips", context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips_cmd")}, + {"Flow Launcher UserData Folder", context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location_cmd")} + }; } private List Commands() @@ -89,7 +133,7 @@ namespace Flow.Launcher.Plugin.Sys { new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer_cmd"), + Title = "Shutdown", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe7e8"), IcoPath = "Images\\shutdown.png", @@ -109,7 +153,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer_cmd"), + Title = "Restart", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe777"), IcoPath = "Images\\restart.png", @@ -129,7 +173,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced_cmd"), + Title = "Restart With Advanced Boot Options", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xecc5"), IcoPath = "Images\\restart_advanced.png", @@ -139,7 +183,7 @@ namespace Flow.Launcher.Plugin.Sys context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"), context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"), MessageBoxButton.YesNo, MessageBoxImage.Warning); - + if (result == MessageBoxResult.Yes) Process.Start("shutdown", "/r /o /t 0"); @@ -148,7 +192,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_log_off_cmd"), + Title = "Log Off/Sign Out", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_log_off"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe77b"), IcoPath = "Images\\logoff.png", @@ -158,7 +202,7 @@ namespace Flow.Launcher.Plugin.Sys context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"), context.API.GetTranslation("flowlauncher_plugin_sys_log_off"), MessageBoxButton.YesNo, MessageBoxImage.Warning); - + if (result == MessageBoxResult.Yes) ExitWindowsEx(EWX_LOGOFF, 0); @@ -167,7 +211,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_lock_cmd"), + Title = "Lock", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_lock"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe72e"), IcoPath = "Images\\lock.png", @@ -179,7 +223,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_sleep_cmd"), + Title = "Sleep", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_sleep"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xec46"), IcoPath = "Images\\sleep.png", @@ -187,7 +231,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate_cmd"), + Title = "Hibernate", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate"), Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe945"), IcoPath = "Images\\hibernate.png", @@ -198,13 +242,13 @@ namespace Flow.Launcher.Plugin.Sys info.UseShellExecute = true; ShellCommand.Execute(info); - + return true; } }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_explorer_cmd"), + Title = "Index Option", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_indexoption"), IcoPath = "Images\\indexoption.png", Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe773"), @@ -219,7 +263,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin_cmd"), + Title = "Empty Recycle Bin", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin"), IcoPath = "Images\\recyclebin.png", Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"), @@ -242,7 +286,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin_cmd"), + Title = "Open Recycle Bin", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin"), IcoPath = "Images\\openrecyclebin.png", Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"), @@ -257,7 +301,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_exit_cmd"), + Title = "Exit", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_exit"), IcoPath = "Images\\app.png", Action = c => @@ -268,7 +312,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings_cmd"), + Title = "Save Settings", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings"), IcoPath = "Images\\app.png", Action = c => @@ -281,7 +325,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_restart_cmd"), + Title = "Restart Flow Launcher", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart"), IcoPath = "Images\\app.png", Action = c => @@ -292,7 +336,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_setting_cmd"), + Title = "Settings", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_setting"), IcoPath = "Images\\app.png", Action = c => @@ -303,7 +347,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data_cmd"), + Title = "Reload Plugin Data", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data"), IcoPath = "Images\\app.png", Action = c => @@ -317,13 +361,13 @@ namespace Flow.Launcher.Plugin.Sys context.API.GetTranslation( "flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")), System.Threading.Tasks.TaskScheduler.Current); - + return true; } }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update_cmd"), + Title = "Check For Update", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update"), IcoPath = "Images\\checkupdate.png", Action = c => @@ -335,7 +379,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location_cmd"), + Title = "Open Log Location", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location"), IcoPath = "Images\\app.png", Action = c => @@ -347,7 +391,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips_cmd"), + Title = "Flow Launcher Tips", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips"), IcoPath = "Images\\app.png", Action = c => @@ -358,7 +402,7 @@ namespace Flow.Launcher.Plugin.Sys }, new Result { - Title = context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location_cmd"), + Title = "Flow Launcher UserData Folder", SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location"), IcoPath = "Images\\app.png", Action = c => From 0af311f80c780daae0c1eeee745011c4d38538c3 Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Tue, 16 Jan 2024 21:03:57 +0100 Subject: [PATCH 4/7] Update dictionary value Signed-off-by: Florian Grabmeier --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 725fd492c..5e171abed 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -94,35 +94,36 @@ namespace Flow.Launcher.Plugin.Sys return "Title Not Found"; } + var translatedTitle = context.API.GetTranslation(pair.Value); var englishTitleMatch = StringMatcher.FuzzySearch(query.Search, pair.Key); - var translatedTitleMatch = StringMatcher.FuzzySearch(query.Search, pair.Value); + var translatedTitleMatch = StringMatcher.FuzzySearch(query.Search, translatedTitle); - return englishTitleMatch.Score >= translatedTitleMatch.Score ? pair.Key : pair.Value; + return englishTitleMatch.Score >= translatedTitleMatch.Score ? pair.Key : translatedTitle; } public void Init(PluginInitContext context) { this.context = context; KeywordTitleMappings = new Dictionary{ - {"Shutdown", context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer_cmd")}, - {"Restart", context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer_cmd")}, - {"Restart With Advanced Boot Options", context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced_cmd")}, - {"Log Off/Sign Out", context.API.GetTranslation("flowlauncher_plugin_sys_log_off_cmd")}, - {"Lock", context.API.GetTranslation("flowlauncher_plugin_sys_lock_cmd")}, - {"Sleep", context.API.GetTranslation("flowlauncher_plugin_sys_sleep_cmd")}, - {"Hibernate", context.API.GetTranslation("flowlauncher_plugin_sys_hibernate_cmd")}, - {"Index Option", context.API.GetTranslation("flowlauncher_plugin_sys_indexoption_cmd")}, - {"Empty Recycle Bin", context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin_cmd")}, - {"Open Recycle Bin", context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin_cmd")}, - {"Exit", context.API.GetTranslation("flowlauncher_plugin_sys_exit_cmd")}, - {"Save Settings", context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings_cmd")}, - {"Restart Flow Launcher", context.API.GetTranslation("flowlauncher_plugin_sys_restart_cmd")}, - {"Settings", context.API.GetTranslation("flowlauncher_plugin_sys_setting_cmd")}, - {"Reload Plugin Data", context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data_cmd")}, - {"Check For Update", context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update_cmd")}, - {"Open Log Location", context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location_cmd")}, - {"Flow Launcher Tips", context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips_cmd")}, - {"Flow Launcher UserData Folder", context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location_cmd")} + {"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"}, + {"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"}, + {"Restart With Advanced Boot Options", "flowlauncher_plugin_sys_restart_advanced_cmd"}, + {"Log Off/Sign Out", "flowlauncher_plugin_sys_log_off_cmd"}, + {"Lock", "flowlauncher_plugin_sys_lock_cmd"}, + {"Sleep", "flowlauncher_plugin_sys_sleep_cmd"}, + {"Hibernate", "flowlauncher_plugin_sys_hibernate_cmd"}, + {"Index Option", "flowlauncher_plugin_sys_indexoption_cmd"}, + {"Empty Recycle Bin", "flowlauncher_plugin_sys_emptyrecyclebin_cmd"}, + {"Open Recycle Bin", "flowlauncher_plugin_sys_openrecyclebin_cmd"}, + {"Exit", "flowlauncher_plugin_sys_exit_cmd"}, + {"Save Settings", "flowlauncher_plugin_sys_save_all_settings_cmd"}, + {"Restart Flow Launcher", "flowlauncher_plugin_sys_restart_cmd"}, + {"Settings", "flowlauncher_plugin_sys_setting_cmd"}, + {"Reload Plugin Data", "flowlauncher_plugin_sys_reload_plugin_data_cmd"}, + {"Check For Update", "flowlauncher_plugin_sys_check_for_update_cmd"}, + {"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"}, + {"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"}, + {"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"} }; } From b2b9f7caa57c546510fedeb413f3889c60466879 Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Tue, 16 Jan 2024 21:04:47 +0100 Subject: [PATCH 5/7] Add toggle game mode command Signed-off-by: Florian Grabmeier --- Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml | 1 + Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index 3d43fc619..282a0e809 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -26,6 +26,7 @@ Open Log Location Flow Launcher Tips Flow Launcher UserData Folder + Toggle Game Mode Shutdown Computer diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 5e171abed..f532d82ba 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -123,7 +123,8 @@ namespace Flow.Launcher.Plugin.Sys {"Check For Update", "flowlauncher_plugin_sys_check_for_update_cmd"}, {"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"}, {"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"}, - {"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"} + {"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"}, + {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"} }; } From 04e551d8bf5157f3764c1f40ccd4e98fd89c3161 Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Thu, 18 Jan 2024 08:53:48 +0100 Subject: [PATCH 6/7] Replace TryGetValue Signed-off-by: Florian Grabmeier --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index f532d82ba..53f08301f 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -84,21 +84,23 @@ namespace Flow.Launcher.Plugin.Sys private string GetDynamicTitle(Query query, Result result) { - var pair = KeywordTitleMappings - .Where(kvp => kvp.Key == result.Title && kvp.Key != kvp.Value) - .FirstOrDefault(); - - if (pair.Equals(default)) + if (!KeywordTitleMappings.TryGetValue(result.Title, out var translationKey)) { Log.Error($"Dynamic Title not found for: {result.Title}"); return "Title Not Found"; } - var translatedTitle = context.API.GetTranslation(pair.Value); - var englishTitleMatch = StringMatcher.FuzzySearch(query.Search, pair.Key); + var translatedTitle = context.API.GetTranslation(translationKey); + + if (result.Title == translatedTitle) + { + return result.Title; + } + + var englishTitleMatch = StringMatcher.FuzzySearch(query.Search, result.Title); var translatedTitleMatch = StringMatcher.FuzzySearch(query.Search, translatedTitle); - return englishTitleMatch.Score >= translatedTitleMatch.Score ? pair.Key : translatedTitle; + return englishTitleMatch.Score >= translatedTitleMatch.Score ? result.Title : translatedTitle; } public void Init(PluginInitContext context) From 82a8d56206a70bf370a5ba61e3393e5d3e231d35 Mon Sep 17 00:00:00 2001 From: flox_x <93255373+flooxo@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:30:23 +0100 Subject: [PATCH 7/7] Update log message Co-authored-by: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 53f08301f..1ec07915d 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -86,7 +86,7 @@ namespace Flow.Launcher.Plugin.Sys { if (!KeywordTitleMappings.TryGetValue(result.Title, out var translationKey)) { - Log.Error($"Dynamic Title not found for: {result.Title}"); + Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Dynamic Title not found for: {result.Title}"); return "Title Not Found"; }