From bc0cde289c2af505f1ea7890173dc2226486dbb9 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 18:20:25 +0800 Subject: [PATCH 1/8] Add translations for system plugin command column --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 28747cc7cf1..05687701db7 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -28,8 +28,12 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n public Control CreateSettingPanel() { - var results = Commands(); - return new SysSettings(results); + var commands = Commands(); + foreach (var c in commands) + { + c.Title = GetDynamicTitle(null, c); + } + return new SysSettings(commands); } public List Query(Query query) @@ -73,6 +77,11 @@ private string GetDynamicTitle(Query query, Result result) var translatedTitle = context.API.GetTranslation(translationKey); + if (query == null) + { + return translatedTitle; + } + if (result.Title == translatedTitle) { return result.Title; From 01e8be779ce47dea22ae8d6a959baadb3aa2df46 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 19:30:51 +0800 Subject: [PATCH 2/8] Fix FL settings issue --- Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 38619cbbc2c..e67b4e5c5c8 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -2,7 +2,7 @@ using System.Linq; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; -using Flow.Launcher.Infrastructure.UserSettings; +using FLSettings = Flow.Launcher.Infrastructure.UserSettings.Settings; namespace Flow.Launcher.Plugin.Sys { @@ -10,7 +10,7 @@ public class ThemeSelector { public const string Keyword = "fltheme"; - private readonly Settings _settings; + private readonly FLSettings _settings; private readonly Theme _theme; private readonly PluginInitContext _context; @@ -43,7 +43,7 @@ public ThemeSelector(PluginInitContext context) { _context = context; _theme = Ioc.Default.GetRequiredService(); - _settings = Ioc.Default.GetRequiredService(); + _settings = Ioc.Default.GetRequiredService(); } public List Query(Query query) From 8335821ad080818586f3a09d23a72b4c09da0edc Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 22:02:45 +0800 Subject: [PATCH 3/8] Clean up codes --- .../SettingsViewModel.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs index a2538893bc9..e07e30cb2b6 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs @@ -1,21 +1,12 @@ -using Flow.Launcher.Infrastructure.Storage; - -namespace Flow.Launcher.Plugin.WebSearch +namespace Flow.Launcher.Plugin.WebSearch { public class SettingsViewModel { - private readonly PluginJsonStorage _storage; - public SettingsViewModel(Settings settings) { Settings = settings; } public Settings Settings { get; } - - public void Save() - { - _storage.Save(); - } } -} \ No newline at end of file +} From e0f02a0d7bc62ba0b2c84359cf952545c963ec14 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 22:34:50 +0800 Subject: [PATCH 4/8] Initialize localized grid & Edit button --- Plugins/Flow.Launcher.Plugin.Sys/Command.cs | 17 +++ .../Languages/en.xaml | 5 +- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 103 +++++++++----- Plugins/Flow.Launcher.Plugin.Sys/Settings.cs | 127 ++++++++++++++++++ .../SettingsViewModel.cs | 12 ++ .../Flow.Launcher.Plugin.Sys/SysSettings.xaml | 38 +++++- .../SysSettings.xaml.cs | 44 ++++-- 7 files changed, 301 insertions(+), 45 deletions(-) create mode 100644 Plugins/Flow.Launcher.Plugin.Sys/Command.cs create mode 100644 Plugins/Flow.Launcher.Plugin.Sys/Settings.cs create mode 100644 Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Command.cs b/Plugins/Flow.Launcher.Plugin.Sys/Command.cs new file mode 100644 index 00000000000..84f5f046fb9 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/Command.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace Flow.Launcher.Plugin.Sys +{ + public class Command : BaseModel + { + public string Key { get; set; } + + [JsonIgnore] + public string Name { get; set; } + + [JsonIgnore] + public string Description { get; set; } + + public string Keyword { get; set; } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index 2a266f8f651..e1d83fa382b 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -4,8 +4,9 @@ xmlns:system="clr-namespace:System;assembly=mscorlib"> - Command + Name Description + Command Shutdown Restart @@ -29,6 +30,8 @@ Toggle Game Mode Set the Flow Launcher Theme + Edit + Shutdown Computer Restart Computer diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 05687701db7..ef9da27192d 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -19,8 +19,36 @@ namespace Flow.Launcher.Plugin.Sys public class Main : IPlugin, ISettingProvider, IPluginI18n { private PluginInitContext context; + private Settings settings; private ThemeSelector themeSelector; - private Dictionary KeywordTitleMappings = new Dictionary(); + + private readonly Dictionary KeywordTitleMappings = new() + { + {"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"}, + {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}, + {"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"} + }; + private readonly Dictionary KeywordDescriptionMappings = new(); + + private SettingsViewModel _viewModel; // SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons. // SHTDN_REASON_FLAG_PLANNED marks the shutdown as planned rather than an unexpected shutdown or failure @@ -28,12 +56,8 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n public Control CreateSettingPanel() { - var commands = Commands(); - foreach (var c in commands) - { - c.Title = GetDynamicTitle(null, c); - } - return new SysSettings(commands); + UpdateLocalizedNameDescription(false); + return new SysSettings(_viewModel); } public List Query(Query query) @@ -67,6 +91,29 @@ public List Query(Query query) return results; } + private string GetTitle(string key) + { + if (!KeywordTitleMappings.TryGetValue(key, out var translationKey)) + { + Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Title not found for: {key}"); + return "Title Not Found"; + } + + return context.API.GetTranslation(translationKey); + } + + private string GetDescription(string key) + { + if (!KeywordDescriptionMappings.TryGetValue(key, out var translationKey)) + { + Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Description not found for: {key}"); + return "Description Not Found"; + } + + return context.API.GetTranslation(translationKey); + } + + [Obsolete] private string GetDynamicTitle(Query query, Result result) { if (!KeywordTitleMappings.TryGetValue(result.Title, out var translationKey)) @@ -96,30 +143,26 @@ private string GetDynamicTitle(Query query, Result result) public void Init(PluginInitContext context) { this.context = context; + settings = context.API.LoadSettingJsonStorage(); + _viewModel = new SettingsViewModel(settings); themeSelector = new ThemeSelector(context); - KeywordTitleMappings = new Dictionary{ - {"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"}, - {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}, - {"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"} - }; + foreach (string key in KeywordTitleMappings.Keys) + { + // Remove _cmd in the last of the strings + KeywordDescriptionMappings[key] = KeywordTitleMappings[key][..^4]; + } + } + + private void UpdateLocalizedNameDescription(bool force) + { + if (string.IsNullOrEmpty(settings.Commands[0].Name) || force) + { + foreach (var c in settings.Commands) + { + c.Name = GetTitle(c.Key); + c.Description = GetDescription(c.Key); + } + } } private static unsafe bool EnableShutdownPrivilege() diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs b/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs new file mode 100644 index 00000000000..f39e6d65fe0 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs @@ -0,0 +1,127 @@ +using System.Collections.ObjectModel; +using System.Text.Json.Serialization; + +namespace Flow.Launcher.Plugin.Sys; + +public class Settings : BaseModel +{ + public Settings() + { + if (Commands.Count > 0) + { + SelectedCommand = Commands[0]; + } + } + + public ObservableCollection Commands { get; set; } = new ObservableCollection + { + new() + { + Key = "Shutdown", + Keyword = "Shutdown" + }, + new() + { + Key = "Restart", + Keyword = "Restart" + }, + new() + { + Key = "Restart With Advanced Boot Options", + Keyword = "Restart With Advanced Boot Options" + }, + new() + { + Key = "Log Off/Sign Out", + Keyword = "Log Off/Sign Out" + }, + new() + { + Key = "Lock", + Keyword = "Lock" + }, + new() + { + Key = "Sleep", + Keyword = "Sleep" + }, + new() + { + Key = "Hibernate", + Keyword = "Hibernate" + }, + new() + { + Key = "Index Option", + Keyword = "Index Option" + }, + new() + { + Key = "Empty Recycle Bin", + Keyword = "Empty Recycle Bin" + }, + new() + { + Key = "Open Recycle Bin", + Keyword = "Open Recycle Bin" + }, + new() + { + Key = "Exit", + Keyword = "Exit" + }, + new() + { + Key = "Save Settings", + Keyword = "Save Settings" + }, + new() + { + Key = "Restart Flow Launcher", + Keyword = "Restart Flow Launcher" + }, + new() + { + Key = "Settings", + Keyword = "Settings" + }, + new() + { + Key = "Reload Plugin Data", + Keyword = "Reload Plugin Data" + }, + new() + { + Key = "Check For Update", + Keyword = "Check For Update" + }, + new() + { + Key = "Open Log Location", + Keyword = "Open Log Location" + }, + new() + { + Key = "Flow Launcher Tips", + Keyword = "Flow Launcher Tips" + }, + new() + { + Key = "Flow Launcher UserData Folder", + Keyword = "Flow Launcher UserData Folder" + }, + new() + { + Key = "Toggle Game Mode", + Keyword = "Toggle Game Mode" + }, + new() + { + Key = "Set Flow Launcher Theme", + Keyword = "Set Flow Launcher Theme" + } + }; + + [JsonIgnore] + public Command SelectedCommand { get; set; } +} diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs new file mode 100644 index 00000000000..0755dffa923 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs @@ -0,0 +1,12 @@ +namespace Flow.Launcher.Plugin.Sys +{ + public class SettingsViewModel + { + public SettingsViewModel(Settings settings) + { + Settings = settings; + } + + public Settings Settings { get; } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml index f806900dedc..67e840e5358 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml @@ -4,36 +4,66 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vm="clr-namespace:Flow.Launcher.Plugin.Sys" + d:DataContext="{d:DesignInstance vm:SettingsViewModel}" d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"> - + + + + + + - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +