Fix plugin events not being called and clean up InstallationManager.cs
This commit is contained in:
parent
9cffa66a01
commit
8a15ad160b
|
@ -10,12 +10,15 @@ using System.Runtime.Serialization;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Data.Events;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Common.Updates;
|
using MediaBrowser.Common.Updates;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using MediaBrowser.Controller.Events;
|
||||||
|
using MediaBrowser.Controller.Events.Updates;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.Net;
|
using MediaBrowser.Model.Net;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
|
@ -34,6 +37,7 @@ namespace Emby.Server.Implementations.Updates
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ILogger<InstallationManager> _logger;
|
private readonly ILogger<InstallationManager> _logger;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
private readonly IEventManager _eventManager;
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
|
@ -63,23 +67,20 @@ namespace Emby.Server.Implementations.Updates
|
||||||
ILogger<InstallationManager> logger,
|
ILogger<InstallationManager> logger,
|
||||||
IApplicationHost appHost,
|
IApplicationHost appHost,
|
||||||
IApplicationPaths appPaths,
|
IApplicationPaths appPaths,
|
||||||
|
IEventManager eventManager,
|
||||||
IHttpClientFactory httpClientFactory,
|
IHttpClientFactory httpClientFactory,
|
||||||
IJsonSerializer jsonSerializer,
|
IJsonSerializer jsonSerializer,
|
||||||
IServerConfigurationManager config,
|
IServerConfigurationManager config,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IZipClient zipClient)
|
IZipClient zipClient)
|
||||||
{
|
{
|
||||||
if (logger == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentInstallations = new List<(InstallationInfo, CancellationTokenSource)>();
|
_currentInstallations = new List<(InstallationInfo, CancellationTokenSource)>();
|
||||||
_completedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
|
_completedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
|
||||||
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_applicationHost = appHost;
|
_applicationHost = appHost;
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
|
_eventManager = eventManager;
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_config = config;
|
_config = config;
|
||||||
|
@ -87,27 +88,6 @@ namespace Emby.Server.Implementations.Updates
|
||||||
_zipClient = zipClient;
|
_zipClient = zipClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<InstallationInfo> PackageInstalling;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<InstallationInfo> PackageInstallationCompleted;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<InstallationInfo> PackageInstallationCancelled;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<IPlugin> PluginUninstalled;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<InstallationInfo> PluginUpdated;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler<InstallationInfo> PluginInstalled;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
|
public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
|
||||||
|
|
||||||
|
@ -256,11 +236,11 @@ namespace Emby.Server.Implementations.Updates
|
||||||
|
|
||||||
var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
|
var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
|
||||||
|
|
||||||
PackageInstalling?.Invoke(this, package);
|
await _eventManager.PublishAsync(new PluginInstallingEventArgs(package)).ConfigureAwait(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await InstallPackageInternal(package, linkedToken).ConfigureAwait(false);
|
var isUpdate = await InstallPackageInternal(package, linkedToken).ConfigureAwait(false);
|
||||||
|
|
||||||
lock (_currentInstallationsLock)
|
lock (_currentInstallationsLock)
|
||||||
{
|
{
|
||||||
|
@ -268,8 +248,11 @@ namespace Emby.Server.Implementations.Updates
|
||||||
}
|
}
|
||||||
|
|
||||||
_completedInstallationsInternal.Add(package);
|
_completedInstallationsInternal.Add(package);
|
||||||
|
await _eventManager.PublishAsync(isUpdate
|
||||||
|
? (GenericEventArgs<InstallationInfo>)new PluginUpdatedEventArgs(package)
|
||||||
|
: new PluginInstalledEventArgs(package)).ConfigureAwait(false);
|
||||||
|
|
||||||
PackageInstallationCompleted?.Invoke(this, package);
|
_applicationHost.NotifyPendingRestart();
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
@ -280,7 +263,7 @@ namespace Emby.Server.Implementations.Updates
|
||||||
|
|
||||||
_logger.LogInformation("Package installation cancelled: {0} {1}", package.Name, package.Version);
|
_logger.LogInformation("Package installation cancelled: {0} {1}", package.Name, package.Version);
|
||||||
|
|
||||||
PackageInstallationCancelled?.Invoke(this, package);
|
await _eventManager.PublishAsync(new PluginInstallationCancelledEventArgs(package)).ConfigureAwait(false);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
@ -293,11 +276,11 @@ namespace Emby.Server.Implementations.Updates
|
||||||
_currentInstallations.Remove(tuple);
|
_currentInstallations.Remove(tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageInstallationFailed?.Invoke(this, new InstallationFailedEventArgs
|
await _eventManager.PublishAsync(new InstallationFailedEventArgs
|
||||||
{
|
{
|
||||||
InstallationInfo = package,
|
InstallationInfo = package,
|
||||||
Exception = ex
|
Exception = ex
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +297,7 @@ namespace Emby.Server.Implementations.Updates
|
||||||
/// <param name="package">The package.</param>
|
/// <param name="package">The package.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns><see cref="Task" />.</returns>
|
/// <returns><see cref="Task" />.</returns>
|
||||||
private async Task InstallPackageInternal(InstallationInfo package, CancellationToken cancellationToken)
|
private async Task<bool> InstallPackageInternal(InstallationInfo package, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// Set last update time if we were installed before
|
// Set last update time if we were installed before
|
||||||
IPlugin plugin = _applicationHost.Plugins.FirstOrDefault(p => p.Id == package.Guid)
|
IPlugin plugin = _applicationHost.Plugins.FirstOrDefault(p => p.Id == package.Guid)
|
||||||
|
@ -324,20 +307,9 @@ namespace Emby.Server.Implementations.Updates
|
||||||
await PerformPackageInstallation(package, cancellationToken).ConfigureAwait(false);
|
await PerformPackageInstallation(package, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Do plugin-specific processing
|
// Do plugin-specific processing
|
||||||
if (plugin == null)
|
_logger.LogInformation(plugin == null ? "New plugin installed: {0} {1}" : "Plugin updated: {0} {1}", package.Name, package.Version);
|
||||||
{
|
|
||||||
_logger.LogInformation("New plugin installed: {0} {1}", package.Name, package.Version);
|
|
||||||
|
|
||||||
PluginInstalled?.Invoke(this, package);
|
return plugin != null;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Plugin updated: {0} {1}", package.Name, package.Version);
|
|
||||||
|
|
||||||
PluginUpdated?.Invoke(this, package);
|
|
||||||
}
|
|
||||||
|
|
||||||
_applicationHost.NotifyPendingRestart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PerformPackageInstallation(InstallationInfo package, CancellationToken cancellationToken)
|
private async Task PerformPackageInstallation(InstallationInfo package, CancellationToken cancellationToken)
|
||||||
|
@ -438,7 +410,7 @@ namespace Emby.Server.Implementations.Updates
|
||||||
_config.SaveConfiguration();
|
_config.SaveConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginUninstalled?.Invoke(this, plugin);
|
_eventManager.Publish(new PluginUninstalledEventArgs(plugin));
|
||||||
|
|
||||||
_applicationHost.NotifyPendingRestart();
|
_applicationHost.NotifyPendingRestart();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,29 +11,6 @@ namespace MediaBrowser.Common.Updates
|
||||||
{
|
{
|
||||||
public interface IInstallationManager : IDisposable
|
public interface IInstallationManager : IDisposable
|
||||||
{
|
{
|
||||||
event EventHandler<InstallationInfo> PackageInstalling;
|
|
||||||
|
|
||||||
event EventHandler<InstallationInfo> PackageInstallationCompleted;
|
|
||||||
|
|
||||||
event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
|
|
||||||
|
|
||||||
event EventHandler<InstallationInfo> PackageInstallationCancelled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Occurs when a plugin is uninstalled.
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler<IPlugin> PluginUninstalled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Occurs when a plugin is updated.
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler<InstallationInfo> PluginUpdated;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Occurs when a plugin is installed.
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler<InstallationInfo> PluginInstalled;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the completed installations.
|
/// Gets the completed installations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user