Skip to content

Commit

Permalink
Merge pull request #7 from Foxtrek64/Feature/FilterPluginAssemblies
Browse files Browse the repository at this point in the history
Accept Predicate to Filter Plugins
  • Loading branch information
Nihlus authored Oct 25, 2024
2 parents d04be3c + fca6cbf commit 394b645
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Remora.Plugins/Services/PluginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public PluginService(IOptions<PluginServiceOptions> options)
/// means that <see cref="PluginTree.Branches"/> will contain dependency-free plugins, with subsequent
/// dependents below them (recursively).
/// </summary>
/// <param name="filter">If provided, any plugins must match the defined predicate to be added to the <see cref="PluginTree"/>.</param>
/// <returns>The dependency tree.</returns>
[PublicAPI, Pure]
public PluginTree LoadPluginTree()
public PluginTree LoadPluginTree(Predicate<IPluginDescriptor>? filter = null)
{
var pluginAssemblies = LoadAvailablePluginAssemblies().ToList();
var pluginsWithDependencies = pluginAssemblies.ToDictionary
Expand Down Expand Up @@ -104,12 +105,17 @@ bool IsDirectDependency(Assembly assembly, Assembly dependency)
{
var current = sorted[0];
var loadDescriptorResult = LoadPluginDescriptor(current);
if (!loadDescriptorResult.IsSuccess)
if (!loadDescriptorResult.IsDefined(out IPluginDescriptor? pluginDescriptor))
{
continue;
}

var node = new PluginTreeNode(loadDescriptorResult.Entity);
if (!filter?.Invoke(pluginDescriptor) ?? false)
{
continue;
}

var node = new PluginTreeNode(pluginDescriptor);

var dependencies = pluginsWithDependencies[current].ToList();
if (!dependencies.Any())
Expand Down

0 comments on commit 394b645

Please sign in to comment.