@@ -25,6 +25,7 @@ public static class PluginManager
2525 private static readonly string ClassName = nameof ( PluginManager ) ;
2626
2727 private static IEnumerable < PluginPair > _contextMenuPlugins ;
28+ private static IEnumerable < PluginPair > _homePlugins ;
2829
2930 public static List < PluginPair > AllPlugins { get ; private set ; }
3031 public static readonly HashSet < PluginPair > GlobalPlugins = new ( ) ;
@@ -220,13 +221,16 @@ public static async Task InitializePluginsAsync()
220221 {
221222 API . LogException ( ClassName , $ "Fail to Init plugin: { pair . Metadata . Name } ", e ) ;
222223 pair . Metadata . Disabled = true ;
224+ pair . Metadata . HomeDisabled = true ;
223225 failedPlugins . Enqueue ( pair ) ;
224226 }
225227 } ) ) ;
226228
227229 await Task . WhenAll ( InitTasks ) ;
228230
229231 _contextMenuPlugins = GetPluginsForInterface < IContextMenu > ( ) ;
232+ _homePlugins = GetPluginsForInterface < IAsyncHomeQuery > ( ) ;
233+
230234 foreach ( var plugin in AllPlugins )
231235 {
232236 // set distinct on each plugin's action keywords helps only firing global(*) and action keywords once where a plugin
@@ -277,6 +281,11 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query, bool qui
277281 } ;
278282 }
279283
284+ public static ICollection < PluginPair > ValidPluginsForHomeQuery ( )
285+ {
286+ return _homePlugins . ToList ( ) ;
287+ }
288+
280289 public static async Task < List < Result > > QueryForPluginAsync ( PluginPair pair , Query query , CancellationToken token )
281290 {
282291 var results = new List < Result > ( ) ;
@@ -321,6 +330,36 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
321330 return results ;
322331 }
323332
333+ public static async Task < List < Result > > QueryHomeForPluginAsync ( PluginPair pair , Query query , CancellationToken token )
334+ {
335+ var results = new List < Result > ( ) ;
336+ var metadata = pair . Metadata ;
337+
338+ try
339+ {
340+ var milliseconds = await API . StopwatchLogDebugAsync ( ClassName , $ "Cost for { metadata . Name } ",
341+ async ( ) => results = await ( ( IAsyncHomeQuery ) pair . Plugin ) . HomeQueryAsync ( token ) . ConfigureAwait ( false ) ) ;
342+
343+ token . ThrowIfCancellationRequested ( ) ;
344+ if ( results == null )
345+ return null ;
346+ UpdatePluginMetadata ( results , metadata , query ) ;
347+
348+ token . ThrowIfCancellationRequested ( ) ;
349+ }
350+ catch ( OperationCanceledException )
351+ {
352+ // null will be fine since the results will only be added into queue if the token hasn't been cancelled
353+ return null ;
354+ }
355+ catch ( Exception e )
356+ {
357+ API . LogException ( ClassName , $ "Failed to query home for plugin: { metadata . Name } ", e ) ;
358+ return null ;
359+ }
360+ return results ;
361+ }
362+
324363 public static async Task < List < QuickSwitchResult > > QueryQuickSwitchForPluginAsync ( PluginPair pair , Query query , CancellationToken token )
325364 {
326365 var results = new List < QuickSwitchResult > ( ) ;
@@ -411,6 +450,11 @@ public static List<Result> GetContextMenusForPlugin(Result result)
411450 return results ;
412451 }
413452
453+ public static bool IsHomePlugin ( string id )
454+ {
455+ return _homePlugins . Any ( p => p . Metadata . ID == id ) ;
456+ }
457+
414458 public static bool ActionKeywordRegistered ( string actionKeyword )
415459 {
416460 // this method is only checking for action keywords (defined as not '*') registration
0 commit comments