@@ -19,10 +19,6 @@ public static class PluginManager
1919 {
2020 private static IEnumerable < PluginPair > _contextMenuPlugins ;
2121
22- /// <summary>
23- /// Directories that will hold Flow Launcher plugin directory
24- /// </summary>
25-
2622 public static List < PluginPair > AllPlugins { get ; private set ; }
2723 public static readonly List < PluginPair > GlobalPlugins = new List < PluginPair > ( ) ;
2824 public static readonly Dictionary < string , PluginPair > NonGlobalPlugins = new Dictionary < string , PluginPair > ( ) ;
@@ -32,27 +28,18 @@ public static class PluginManager
3228 // todo happlebao, this should not be public, the indicator function should be embeded
3329 public static PluginsSettings Settings ;
3430 private static List < PluginMetadata > _metadatas ;
35- private static readonly string [ ] Directories = { Constant . PreinstalledDirectory , DataLocation . PluginsDirectory } ;
3631
37- private static void ValidateUserDirectory ( )
38- {
39- if ( ! Directory . Exists ( DataLocation . PluginsDirectory ) )
40- {
41- Directory . CreateDirectory ( DataLocation . PluginsDirectory ) ;
42- }
43- }
32+ /// <summary>
33+ /// Directories that will hold Flow Launcher plugin directory
34+ /// </summary>
35+ private static readonly string [ ] Directories = { Constant . PreinstalledDirectory , DataLocation . PluginsDirectory } ;
4436
4537 private static void DeletePythonBinding ( )
4638 {
4739 const string binding = "flowlauncher.py" ;
48- var directory = DataLocation . PluginsDirectory ;
49- foreach ( var subDirectory in Directory . GetDirectories ( directory ) )
40+ foreach ( var subDirectory in Directory . GetDirectories ( DataLocation . PluginsDirectory ) )
5041 {
51- var path = Path . Combine ( subDirectory , binding ) ;
52- if ( File . Exists ( path ) )
53- {
54- File . Delete ( path ) ;
55- }
42+ File . Delete ( Path . Combine ( subDirectory , binding ) ) ;
5643 }
5744 }
5845
@@ -76,7 +63,8 @@ public static void ReloadData()
7663
7764 static PluginManager ( )
7865 {
79- ValidateUserDirectory ( ) ;
66+ // validate user directory
67+ Directory . CreateDirectory ( DataLocation . PluginsDirectory ) ;
8068 // force old plugins use new python binding
8169 DeletePythonBinding ( ) ;
8270 }
@@ -132,9 +120,10 @@ public static void InitializePlugins(IPublicAPI api)
132120 GlobalPlugins . Add ( plugin ) ;
133121
134122 // Plugins may have multiple ActionKeywords, eg. WebSearch
135- plugin . Metadata . ActionKeywords . Where ( x => x != Query . GlobalPluginWildcardSign )
136- . ToList ( )
137- . ForEach ( x => NonGlobalPlugins [ x ] = plugin ) ;
123+ plugin . Metadata . ActionKeywords
124+ . Where ( x => x != Query . GlobalPluginWildcardSign )
125+ . ToList ( )
126+ . ForEach ( x => NonGlobalPlugins [ x ] = plugin ) ;
138127 }
139128
140129 if ( failedPlugins . Any ( ) )
@@ -164,9 +153,9 @@ public static List<PluginPair> ValidPluginsForQuery(Query query)
164153
165154 public static List < Result > QueryForPlugin ( PluginPair pair , Query query )
166155 {
156+ var results = new List < Result > ( ) ;
167157 try
168158 {
169- List < Result > results = null ;
170159 var metadata = pair . Metadata ;
171160 var milliseconds = Stopwatch . Debug ( $ "|PluginManager.QueryForPlugin|Cost for { metadata . Name } ", ( ) =>
172161 {
@@ -175,13 +164,12 @@ public static List<Result> QueryForPlugin(PluginPair pair, Query query)
175164 } ) ;
176165 metadata . QueryCount += 1 ;
177166 metadata . AvgQueryTime = metadata . QueryCount == 1 ? milliseconds : ( metadata . AvgQueryTime + milliseconds ) / 2 ;
178- return results ;
179167 }
180168 catch ( Exception e )
181169 {
182170 Log . Exception ( $ "|PluginManager.QueryForPlugin|Exception for plugin <{ pair . Metadata . Name } > when query <{ query } >", e ) ;
183- return new List < Result > ( ) ;
184171 }
172+ return results ;
185173 }
186174
187175 public static void UpdatePluginMetadata ( List < Result > results , PluginMetadata metadata , Query query )
@@ -221,47 +209,34 @@ public static IEnumerable<PluginPair> GetPluginsForInterface<T>() where T : IFea
221209
222210 public static List < Result > GetContextMenusForPlugin ( Result result )
223211 {
212+ var results = new List < Result > ( ) ;
224213 var pluginPair = _contextMenuPlugins . FirstOrDefault ( o => o . Metadata . ID == result . PluginID ) ;
225214 if ( pluginPair != null )
226215 {
227- var metadata = pluginPair . Metadata ;
228216 var plugin = ( IContextMenu ) pluginPair . Plugin ;
229217
230218 try
231219 {
232- var results = plugin . LoadContextMenus ( result ) ;
220+ results = plugin . LoadContextMenus ( result ) ;
233221 foreach ( var r in results )
234222 {
235- r . PluginDirectory = metadata . PluginDirectory ;
236- r . PluginID = metadata . ID ;
223+ r . PluginDirectory = pluginPair . Metadata . PluginDirectory ;
224+ r . PluginID = pluginPair . Metadata . ID ;
237225 r . OriginQuery = result . OriginQuery ;
238226 }
239- return results ;
240227 }
241228 catch ( Exception e )
242229 {
243- Log . Exception ( $ "|PluginManager.GetContextMenusForPlugin|Can't load context menus for plugin <{ metadata . Name } >", e ) ;
244- return new List < Result > ( ) ;
230+ Log . Exception ( $ "|PluginManager.GetContextMenusForPlugin|Can't load context menus for plugin <{ pluginPair . Metadata . Name } >", e ) ;
245231 }
246232 }
247- else
248- {
249- return new List < Result > ( ) ;
250- }
251-
233+ return results ;
252234 }
253235
254236 public static bool ActionKeywordRegistered ( string actionKeyword )
255237 {
256- if ( actionKeyword != Query . GlobalPluginWildcardSign &&
257- NonGlobalPlugins . ContainsKey ( actionKeyword ) )
258- {
259- return true ;
260- }
261- else
262- {
263- return false ;
264- }
238+ return actionKeyword != Query . GlobalPluginWildcardSign
239+ && NonGlobalPlugins . ContainsKey ( actionKeyword ) ;
265240 }
266241
267242 /// <summary>
@@ -299,7 +274,7 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
299274 GlobalPlugins . Remove ( plugin ) ;
300275 }
301276
302- if ( oldActionkeyword != Query . GlobalPluginWildcardSign )
277+ if ( oldActionkeyword != Query . GlobalPluginWildcardSign )
303278 NonGlobalPlugins . Remove ( oldActionkeyword ) ;
304279
305280
0 commit comments