Skip to content

Commit

Permalink
Merge pull request #934 from Bond-009/plugin
Browse files Browse the repository at this point in the history
WIP - Don't require a restart for 75% of plugins
  • Loading branch information
joshuaboniface committed Mar 28, 2019
2 parents cc2edc4 + c6188e2 commit 2dbc115
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@ public virtual bool CanLaunchWebBrowser
/// <value>The logger.</value>
protected ILogger Logger { get; set; }

private IPlugin[] _plugins;

/// <summary>
/// Gets the plugins.
/// </summary>
/// <value>The plugins.</value>
public IPlugin[] Plugins { get; protected set; }
public IPlugin[] Plugins
{
get => _plugins;
protected set => _plugins = value;
}

/// <summary>
/// Gets or sets the logger factory.
Expand Down Expand Up @@ -1036,6 +1042,41 @@ private void SetStaticProperties()
CollectionFolder.JsonSerializer = JsonSerializer;
CollectionFolder.ApplicationHost = this;
AuthenticatedAttribute.AuthService = AuthService;

InstallationManager.PluginInstalled += PluginInstalled;
}

private async void PluginInstalled(object sender, GenericEventArgs<PackageVersionInfo> args)
{
string dir = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(args.Argument.targetFilename));
var types = Directory.EnumerateFiles(dir, "*.dll", SearchOption.TopDirectoryOnly)
.Select(x => Assembly.LoadFrom(x))
.SelectMany(x => x.ExportedTypes)
.Where(x => x.IsClass && !x.IsAbstract && !x.IsInterface && !x.IsGenericType)
.ToList();

types.AddRange(types);

var plugins = types.Where(x => x.IsAssignableFrom(typeof(IPlugin)))
.Select(CreateInstanceSafe)
.Where(x => x != null)
.Cast<IPlugin>()
.Select(LoadPlugin)
.Where(x => x != null)
.ToArray();

int oldLen = _plugins.Length;
Array.Resize<IPlugin>(ref _plugins, _plugins.Length + plugins.Length);
plugins.CopyTo(_plugins, oldLen);

var entries = types.Where(x => x.IsAssignableFrom(typeof(IServerEntryPoint)))
.Select(CreateInstanceSafe)
.Where(x => x != null)
.Cast<IServerEntryPoint>()
.ToList();

await Task.WhenAll(StartEntryPoints(entries, true));
await Task.WhenAll(StartEntryPoints(entries, false));
}

/// <summary>
Expand Down

0 comments on commit 2dbc115

Please sign in to comment.