11using System . Collections . Generic ;
2+ using System . Text . Json . Serialization ;
23using Flow . Launcher . Plugin ;
34
45namespace Flow . Launcher . Infrastructure . UserSettings
56{
67 public class PluginsSettings : BaseModel
78 {
89 private string pythonExecutablePath = string . Empty ;
9- public string PythonExecutablePath {
10- get { return pythonExecutablePath ; }
10+ public string PythonExecutablePath
11+ {
12+ get => pythonExecutablePath ;
1113 set
1214 {
1315 pythonExecutablePath = value ;
@@ -18,25 +20,40 @@ public string PythonExecutablePath {
1820 private string nodeExecutablePath = string . Empty ;
1921 public string NodeExecutablePath
2022 {
21- get { return nodeExecutablePath ; }
23+ get => nodeExecutablePath ;
2224 set
2325 {
2426 nodeExecutablePath = value ;
2527 Constant . NodePath = value ;
2628 }
2729 }
2830
29- public Dictionary < string , Plugin > Plugins { get ; set ; } = new Dictionary < string , Plugin > ( ) ;
31+ /// <summary>
32+ /// Only used for serialization
33+ /// </summary>
34+ public Dictionary < string , Plugin > Plugins { get ; set ; } = new ( ) ;
3035
36+ /// <summary>
37+ /// Update plugin settings with metadata.
38+ /// FL will get default values from metadata first and then load settings to metadata
39+ /// </summary>
40+ /// <param name="metadatas">Parsed plugin metadatas</param>
3141 public void UpdatePluginSettings ( List < PluginMetadata > metadatas )
3242 {
3343 foreach ( var metadata in metadatas )
3444 {
3545 if ( Plugins . TryGetValue ( metadata . ID , out var settings ) )
3646 {
47+ // If settings exist, update settings & metadata value
48+ // update settings values with metadata
3749 if ( string . IsNullOrEmpty ( settings . Version ) )
50+ {
3851 settings . Version = metadata . Version ;
52+ }
53+ settings . DefaultActionKeywords = metadata . ActionKeywords ; // metadata provides default values
54+ settings . DefaultSearchDelayTime = metadata . SearchDelayTime ; // metadata provides default values
3955
56+ // update metadata values with settings
4057 if ( settings . ActionKeywords ? . Count > 0 )
4158 {
4259 metadata . ActionKeywords = settings . ActionKeywords ;
@@ -49,30 +66,65 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
4966 }
5067 metadata . Disabled = settings . Disabled ;
5168 metadata . Priority = settings . Priority ;
69+ metadata . SearchDelayTime = settings . SearchDelayTime ;
5270 }
5371 else
5472 {
73+ // If settings does not exist, create a new one
5574 Plugins [ metadata . ID ] = new Plugin
5675 {
5776 ID = metadata . ID ,
5877 Name = metadata . Name ,
5978 Version = metadata . Version ,
60- ActionKeywords = metadata . ActionKeywords ,
79+ DefaultActionKeywords = metadata . ActionKeywords , // metadata provides default values
80+ ActionKeywords = metadata . ActionKeywords , // use default value
6181 Disabled = metadata . Disabled ,
62- Priority = metadata . Priority
82+ Priority = metadata . Priority ,
83+ DefaultSearchDelayTime = metadata . SearchDelayTime , // metadata provides default values
84+ SearchDelayTime = metadata . SearchDelayTime , // use default value
6385 } ;
6486 }
6587 }
6688 }
89+
90+ public Plugin GetPluginSettings ( string id )
91+ {
92+ if ( Plugins . TryGetValue ( id , out var plugin ) )
93+ {
94+ return plugin ;
95+ }
96+ return null ;
97+ }
98+
99+ public Plugin RemovePluginSettings ( string id )
100+ {
101+ Plugins . Remove ( id , out var plugin ) ;
102+ return plugin ;
103+ }
67104 }
105+
68106 public class Plugin
69107 {
70108 public string ID { get ; set ; }
109+
71110 public string Name { get ; set ; }
111+
72112 public string Version { get ; set ; }
73- public List < string > ActionKeywords { get ; set ; } // a reference of the action keywords from plugin manager
113+
114+ [ JsonIgnore ]
115+ public List < string > DefaultActionKeywords { get ; set ; }
116+
117+ // a reference of the action keywords from plugin manager
118+ public List < string > ActionKeywords { get ; set ; }
119+
74120 public int Priority { get ; set ; }
75121
122+ [ JsonIgnore ]
123+ public SearchDelayTime ? DefaultSearchDelayTime { get ; set ; }
124+
125+ [ JsonConverter ( typeof ( JsonStringEnumConverter ) ) ]
126+ public SearchDelayTime ? SearchDelayTime { get ; set ; }
127+
76128 /// <summary>
77129 /// Used only to save the state of the plugin in settings
78130 /// </summary>
0 commit comments