@@ -25,6 +25,7 @@ public static class PluginManager
25
25
private static readonly string ClassName = nameof ( PluginManager ) ;
26
26
27
27
private static IEnumerable < PluginPair > _contextMenuPlugins ;
28
+ private static IEnumerable < PluginPair > _homePlugins ;
28
29
29
30
public static List < PluginPair > AllPlugins { get ; private set ; }
30
31
public static readonly HashSet < PluginPair > GlobalPlugins = new ( ) ;
@@ -220,13 +221,16 @@ public static async Task InitializePluginsAsync()
220
221
{
221
222
API . LogException ( ClassName , $ "Fail to Init plugin: { pair . Metadata . Name } ", e ) ;
222
223
pair . Metadata . Disabled = true ;
224
+ pair . Metadata . HomeDisabled = true ;
223
225
failedPlugins . Enqueue ( pair ) ;
224
226
}
225
227
} ) ) ;
226
228
227
229
await Task . WhenAll ( InitTasks ) ;
228
230
229
231
_contextMenuPlugins = GetPluginsForInterface < IContextMenu > ( ) ;
232
+ _homePlugins = GetPluginsForInterface < IAsyncHomeQuery > ( ) ;
233
+
230
234
foreach ( var plugin in AllPlugins )
231
235
{
232
236
// 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
277
281
} ;
278
282
}
279
283
284
+ public static ICollection < PluginPair > ValidPluginsForHomeQuery ( )
285
+ {
286
+ return _homePlugins . ToList ( ) ;
287
+ }
288
+
280
289
public static async Task < List < Result > > QueryForPluginAsync ( PluginPair pair , Query query , CancellationToken token )
281
290
{
282
291
var results = new List < Result > ( ) ;
@@ -321,6 +330,36 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
321
330
return results ;
322
331
}
323
332
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
+
324
363
public static async Task < List < QuickSwitchResult > > QueryQuickSwitchForPluginAsync ( PluginPair pair , Query query , CancellationToken token )
325
364
{
326
365
var results = new List < QuickSwitchResult > ( ) ;
@@ -411,6 +450,11 @@ public static List<Result> GetContextMenusForPlugin(Result result)
411
450
return results ;
412
451
}
413
452
453
+ public static bool IsHomePlugin ( string id )
454
+ {
455
+ return _homePlugins . Any ( p => p . Metadata . ID == id ) ;
456
+ }
457
+
414
458
public static bool ActionKeywordRegistered ( string actionKeyword )
415
459
{
416
460
// this method is only checking for action keywords (defined as not '*') registration
0 commit comments