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
@@ -27,17 +28,32 @@ public string NodeExecutablePath
27
28
}
28
29
}
29
30
30
- private Dictionary < string , Plugin > Plugins { get ; set ; } = new ( ) ;
31
+ /// <summary>
32
+ /// Only used for serialization
33
+ /// </summary>
34
+ public Dictionary < string , Plugin > Plugins { get ; set ; } = new ( ) ;
31
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>
32
41
public void UpdatePluginSettings ( List < PluginMetadata > metadatas )
33
42
{
34
43
foreach ( var metadata in metadatas )
35
44
{
36
45
if ( Plugins . TryGetValue ( metadata . ID , out var settings ) )
37
46
{
47
+ // If settings exist, update settings & metadata value
48
+ // update settings values with metadata
38
49
if ( string . IsNullOrEmpty ( settings . Version ) )
50
+ {
39
51
settings . Version = metadata . Version ;
52
+ }
53
+ settings . DefaultActionKeywords = metadata . ActionKeywords ; // metadata provides default values
54
+ settings . DefaultSearchDelay = metadata . SearchDelay ; // metadata provides default values
40
55
56
+ // update metadata values with settings
41
57
if ( settings . ActionKeywords ? . Count > 0 )
42
58
{
43
59
metadata . ActionKeywords = settings . ActionKeywords ;
@@ -54,15 +70,18 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
54
70
}
55
71
else
56
72
{
73
+ // If settings does not exist, create a new one
57
74
Plugins [ metadata . ID ] = new Plugin
58
75
{
59
76
ID = metadata . ID ,
60
77
Name = metadata . Name ,
61
78
Version = metadata . Version ,
62
- ActionKeywords = metadata . ActionKeywords ,
79
+ DefaultActionKeywords = metadata . ActionKeywords , // metadata provides default values
80
+ ActionKeywords = metadata . ActionKeywords , // use default value
63
81
Disabled = metadata . Disabled ,
64
82
Priority = metadata . Priority ,
65
- SearchDelay = metadata . SearchDelay ,
83
+ DefaultSearchDelay = metadata . SearchDelay , // metadata provides default values
84
+ SearchDelay = metadata . SearchDelay , // use default value
66
85
} ;
67
86
}
68
87
}
@@ -73,7 +92,7 @@ public Plugin GetPluginSettings(string id)
73
92
if ( Plugins . TryGetValue ( id , out var plugin ) )
74
93
{
75
94
return plugin ;
76
- }
95
+ }
77
96
return null ;
78
97
}
79
98
@@ -91,8 +110,18 @@ public class Plugin
91
110
public string Name { get ; set ; }
92
111
93
112
public string Version { get ; set ; }
94
- 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
+
95
120
public int Priority { get ; set ; }
121
+
122
+ [ JsonIgnore ]
123
+ public int DefaultSearchDelay { get ; set ; }
124
+
96
125
public int SearchDelay { get ; set ; }
97
126
98
127
/// <summary>
0 commit comments