@@ -19,21 +19,45 @@ namespace Flow.Launcher.Plugin.Sys
19
19
public class Main : IPlugin , ISettingProvider , IPluginI18n
20
20
{
21
21
private PluginInitContext context ;
22
+ private Settings settings ;
22
23
private ThemeSelector themeSelector ;
23
- private Dictionary < string , string > KeywordTitleMappings = new Dictionary < string , string > ( ) ;
24
+
25
+ private readonly Dictionary < string , string > KeywordTitleMappings = new ( )
26
+ {
27
+ { "Shutdown" , "flowlauncher_plugin_sys_shutdown_computer_cmd" } ,
28
+ { "Restart" , "flowlauncher_plugin_sys_restart_computer_cmd" } ,
29
+ { "Restart With Advanced Boot Options" , "flowlauncher_plugin_sys_restart_advanced_cmd" } ,
30
+ { "Log Off/Sign Out" , "flowlauncher_plugin_sys_log_off_cmd" } ,
31
+ { "Lock" , "flowlauncher_plugin_sys_lock_cmd" } ,
32
+ { "Sleep" , "flowlauncher_plugin_sys_sleep_cmd" } ,
33
+ { "Hibernate" , "flowlauncher_plugin_sys_hibernate_cmd" } ,
34
+ { "Index Option" , "flowlauncher_plugin_sys_indexoption_cmd" } ,
35
+ { "Empty Recycle Bin" , "flowlauncher_plugin_sys_emptyrecyclebin_cmd" } ,
36
+ { "Open Recycle Bin" , "flowlauncher_plugin_sys_openrecyclebin_cmd" } ,
37
+ { "Exit" , "flowlauncher_plugin_sys_exit_cmd" } ,
38
+ { "Save Settings" , "flowlauncher_plugin_sys_save_all_settings_cmd" } ,
39
+ { "Restart Flow Launcher" , "flowlauncher_plugin_sys_restart_cmd" } ,
40
+ { "Settings" , "flowlauncher_plugin_sys_setting_cmd" } ,
41
+ { "Reload Plugin Data" , "flowlauncher_plugin_sys_reload_plugin_data_cmd" } ,
42
+ { "Check For Update" , "flowlauncher_plugin_sys_check_for_update_cmd" } ,
43
+ { "Open Log Location" , "flowlauncher_plugin_sys_open_log_location_cmd" } ,
44
+ { "Flow Launcher Tips" , "flowlauncher_plugin_sys_open_docs_tips_cmd" } ,
45
+ { "Flow Launcher UserData Folder" , "flowlauncher_plugin_sys_open_userdata_location_cmd" } ,
46
+ { "Toggle Game Mode" , "flowlauncher_plugin_sys_toggle_game_mode_cmd" } ,
47
+ { "Set Flow Launcher Theme" , "flowlauncher_plugin_sys_theme_selector_cmd" }
48
+ } ;
49
+ private readonly Dictionary < string , string > KeywordDescriptionMappings = new ( ) ;
50
+
51
+ private SettingsViewModel _viewModel ;
24
52
25
53
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons.
26
54
// SHTDN_REASON_FLAG_PLANNED marks the shutdown as planned rather than an unexpected shutdown or failure
27
55
private const SHUTDOWN_REASON REASON = SHUTDOWN_REASON . SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON . SHTDN_REASON_FLAG_PLANNED ;
28
56
29
57
public Control CreateSettingPanel ( )
30
58
{
31
- var commands = Commands ( ) ;
32
- foreach ( var c in commands )
33
- {
34
- c . Title = GetDynamicTitle ( null , c ) ;
35
- }
36
- return new SysSettings ( commands ) ;
59
+ UpdateLocalizedNameDescription ( false ) ;
60
+ return new SysSettings ( _viewModel ) ;
37
61
}
38
62
39
63
public List < Result > Query ( Query query )
@@ -67,6 +91,29 @@ public List<Result> Query(Query query)
67
91
return results ;
68
92
}
69
93
94
+ private string GetTitle ( string key )
95
+ {
96
+ if ( ! KeywordTitleMappings . TryGetValue ( key , out var translationKey ) )
97
+ {
98
+ Log . Error ( "Flow.Launcher.Plugin.Sys.Main" , $ "Title not found for: { key } ") ;
99
+ return "Title Not Found" ;
100
+ }
101
+
102
+ return context . API . GetTranslation ( translationKey ) ;
103
+ }
104
+
105
+ private string GetDescription ( string key )
106
+ {
107
+ if ( ! KeywordDescriptionMappings . TryGetValue ( key , out var translationKey ) )
108
+ {
109
+ Log . Error ( "Flow.Launcher.Plugin.Sys.Main" , $ "Description not found for: { key } ") ;
110
+ return "Description Not Found" ;
111
+ }
112
+
113
+ return context . API . GetTranslation ( translationKey ) ;
114
+ }
115
+
116
+ [ Obsolete ]
70
117
private string GetDynamicTitle ( Query query , Result result )
71
118
{
72
119
if ( ! KeywordTitleMappings . TryGetValue ( result . Title , out var translationKey ) )
@@ -96,30 +143,26 @@ private string GetDynamicTitle(Query query, Result result)
96
143
public void Init ( PluginInitContext context )
97
144
{
98
145
this . context = context ;
146
+ settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
147
+ _viewModel = new SettingsViewModel ( settings ) ;
99
148
themeSelector = new ThemeSelector ( context ) ;
100
- KeywordTitleMappings = new Dictionary < string , string > {
101
- { "Shutdown" , "flowlauncher_plugin_sys_shutdown_computer_cmd" } ,
102
- { "Restart" , "flowlauncher_plugin_sys_restart_computer_cmd" } ,
103
- { "Restart With Advanced Boot Options" , "flowlauncher_plugin_sys_restart_advanced_cmd" } ,
104
- { "Log Off/Sign Out" , "flowlauncher_plugin_sys_log_off_cmd" } ,
105
- { "Lock" , "flowlauncher_plugin_sys_lock_cmd" } ,
106
- { "Sleep" , "flowlauncher_plugin_sys_sleep_cmd" } ,
107
- { "Hibernate" , "flowlauncher_plugin_sys_hibernate_cmd" } ,
108
- { "Index Option" , "flowlauncher_plugin_sys_indexoption_cmd" } ,
109
- { "Empty Recycle Bin" , "flowlauncher_plugin_sys_emptyrecyclebin_cmd" } ,
110
- { "Open Recycle Bin" , "flowlauncher_plugin_sys_openrecyclebin_cmd" } ,
111
- { "Exit" , "flowlauncher_plugin_sys_exit_cmd" } ,
112
- { "Save Settings" , "flowlauncher_plugin_sys_save_all_settings_cmd" } ,
113
- { "Restart Flow Launcher" , "flowlauncher_plugin_sys_restart_cmd" } ,
114
- { "Settings" , "flowlauncher_plugin_sys_setting_cmd" } ,
115
- { "Reload Plugin Data" , "flowlauncher_plugin_sys_reload_plugin_data_cmd" } ,
116
- { "Check For Update" , "flowlauncher_plugin_sys_check_for_update_cmd" } ,
117
- { "Open Log Location" , "flowlauncher_plugin_sys_open_log_location_cmd" } ,
118
- { "Flow Launcher Tips" , "flowlauncher_plugin_sys_open_docs_tips_cmd" } ,
119
- { "Flow Launcher UserData Folder" , "flowlauncher_plugin_sys_open_userdata_location_cmd" } ,
120
- { "Toggle Game Mode" , "flowlauncher_plugin_sys_toggle_game_mode_cmd" } ,
121
- { "Set Flow Launcher Theme" , "flowlauncher_plugin_sys_theme_selector_cmd" }
122
- } ;
149
+ foreach ( string key in KeywordTitleMappings . Keys )
150
+ {
151
+ // Remove _cmd in the last of the strings
152
+ KeywordDescriptionMappings [ key ] = KeywordTitleMappings [ key ] [ ..^ 4 ] ;
153
+ }
154
+ }
155
+
156
+ private void UpdateLocalizedNameDescription ( bool force )
157
+ {
158
+ if ( string . IsNullOrEmpty ( settings . Commands [ 0 ] . Name ) || force )
159
+ {
160
+ foreach ( var c in settings . Commands )
161
+ {
162
+ c . Name = GetTitle ( c . Key ) ;
163
+ c . Description = GetDescription ( c . Key ) ;
164
+ }
165
+ }
123
166
}
124
167
125
168
private static unsafe bool EnableShutdownPrivilege ( )
0 commit comments