1
1
using System . Collections . Generic ;
2
+ using System . Text . Json . Serialization ;
2
3
using Flow . Launcher . Plugin ;
3
4
4
5
namespace Flow . Launcher . Infrastructure . UserSettings
5
6
{
6
7
public class PluginsSettings : BaseModel
7
8
{
8
9
private string pythonExecutablePath = string . Empty ;
9
- public string PythonExecutablePath {
10
- get { return pythonExecutablePath ; }
10
+ public string PythonExecutablePath
11
+ {
12
+ get => pythonExecutablePath ;
11
13
set
12
14
{
13
15
pythonExecutablePath = value ;
@@ -18,25 +20,40 @@ public string PythonExecutablePath {
18
20
private string nodeExecutablePath = string . Empty ;
19
21
public string NodeExecutablePath
20
22
{
21
- get { return nodeExecutablePath ; }
23
+ get => nodeExecutablePath ;
22
24
set
23
25
{
24
26
nodeExecutablePath = value ;
25
27
Constant . NodePath = value ;
26
28
}
27
29
}
28
30
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 ( ) ;
30
35
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>
31
41
public void UpdatePluginSettings ( List < PluginMetadata > metadatas )
32
42
{
33
43
foreach ( var metadata in metadatas )
34
44
{
35
45
if ( Plugins . TryGetValue ( metadata . ID , out var settings ) )
36
46
{
47
+ // If settings exist, update settings & metadata value
48
+ // update settings values with metadata
37
49
if ( string . IsNullOrEmpty ( settings . Version ) )
50
+ {
38
51
settings . Version = metadata . Version ;
52
+ }
53
+ settings . DefaultActionKeywords = metadata . ActionKeywords ; // metadata provides default values
54
+ settings . DefaultSearchDelayTime = metadata . SearchDelayTime ; // metadata provides default values
39
55
56
+ // update metadata values with settings
40
57
if ( settings . ActionKeywords ? . Count > 0 )
41
58
{
42
59
metadata . ActionKeywords = settings . ActionKeywords ;
@@ -49,30 +66,65 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
49
66
}
50
67
metadata . Disabled = settings . Disabled ;
51
68
metadata . Priority = settings . Priority ;
69
+ metadata . SearchDelayTime = settings . SearchDelayTime ;
52
70
}
53
71
else
54
72
{
73
+ // If settings does not exist, create a new one
55
74
Plugins [ metadata . ID ] = new Plugin
56
75
{
57
76
ID = metadata . ID ,
58
77
Name = metadata . Name ,
59
78
Version = metadata . Version ,
60
- ActionKeywords = metadata . ActionKeywords ,
79
+ DefaultActionKeywords = metadata . ActionKeywords , // metadata provides default values
80
+ ActionKeywords = metadata . ActionKeywords , // use default value
61
81
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
63
85
} ;
64
86
}
65
87
}
66
88
}
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
+ }
67
104
}
105
+
68
106
public class Plugin
69
107
{
70
108
public string ID { get ; set ; }
109
+
71
110
public string Name { get ; set ; }
111
+
72
112
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
+
74
120
public int Priority { get ; set ; }
75
121
122
+ [ JsonIgnore ]
123
+ public SearchDelayTime ? DefaultSearchDelayTime { get ; set ; }
124
+
125
+ [ JsonConverter ( typeof ( JsonStringEnumConverter ) ) ]
126
+ public SearchDelayTime ? SearchDelayTime { get ; set ; }
127
+
76
128
/// <summary>
77
129
/// Used only to save the state of the plugin in settings
78
130
/// </summary>
0 commit comments