Changed as suggested.

This commit is contained in:
Greenback 2020-12-15 10:05:04 +00:00
parent dddcfa6dbb
commit 208d545cfe
5 changed files with 50 additions and 16 deletions

View File

@ -53,9 +53,7 @@ namespace Emby.Server.Implementations
_logger = loggerfactory.CreateLogger<PluginManager>(); _logger = loggerfactory.CreateLogger<PluginManager>();
_pluginsPath = pluginsPath; _pluginsPath = pluginsPath;
_appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion)); _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion));
_jsonOptions = JsonDefaults.GetOptions(); _jsonOptions = JsonDefaults.GetCamelCaseOptions();
_jsonOptions.PropertyNameCaseInsensitive = true;
_jsonOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
_config = config; _config = config;
_appHost = appHost; _appHost = appHost;
_imagesPath = imagesPath; _imagesPath = imagesPath;
@ -137,7 +135,8 @@ namespace Emby.Server.Implementations
var plugin = GetPluginByType(pluginServiceRegistrator.Assembly.GetType()); var plugin = GetPluginByType(pluginServiceRegistrator.Assembly.GetType());
if (plugin == null) if (plugin == null)
{ {
throw new NullReferenceException(); _logger.LogError("Unable to find plugin in assembly {Assembly}", pluginServiceRegistrator.Assembly.FullName);
continue;
} }
CheckIfStillSuperceded(plugin); CheckIfStillSuperceded(plugin);
@ -440,6 +439,7 @@ namespace Emby.Server.Implementations
plugin.Instance = (IPlugin)instance; plugin.Instance = (IPlugin)instance;
var manifest = plugin.Manifest; var manifest = plugin.Manifest;
var pluginStr = plugin.Instance.Version.ToString(); var pluginStr = plugin.Instance.Version.ToString();
bool changed = false;
if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal)) if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal))
{ {
// If a plugin without a manifest failed to load due to an external issue (eg config), // If a plugin without a manifest failed to load due to an external issue (eg config),
@ -447,11 +447,17 @@ namespace Emby.Server.Implementations
manifest.Version = pluginStr; manifest.Version = pluginStr;
manifest.Name = plugin.Instance.Name; manifest.Name = plugin.Instance.Name;
manifest.Description = plugin.Instance.Description; manifest.Description = plugin.Instance.Description;
changed = true;
} }
changed = changed || manifest.Status != PluginStatus.Active;
manifest.Status = PluginStatus.Active; manifest.Status = PluginStatus.Active;
if (changed)
{
SaveManifest(manifest, plugin.Path); SaveManifest(manifest, plugin.Path);
} }
}
_logger.LogInformation("Loaded plugin: {PluginName} {PluginVersion}", plugin.Name, plugin.Version); _logger.LogInformation("Loaded plugin: {PluginName} {PluginVersion}", plugin.Name, plugin.Version);
@ -577,8 +583,6 @@ namespace Emby.Server.Implementations
} }
// Auto-create a plugin manifest, so we can disable it, if it fails to load. // Auto-create a plugin manifest, so we can disable it, if it fails to load.
// NOTE: This Plugin is marked as valid for two upgrades, at which point, it can be assumed the
// code base will have changed sufficiently to make it invalid.
manifest = new PluginManifest manifest = new PluginManifest
{ {
Status = PluginStatus.RestartRequired, Status = PluginStatus.RestartRequired,
@ -586,7 +590,6 @@ namespace Emby.Server.Implementations
AutoUpdate = false, AutoUpdate = false,
Guid = metafile.GetMD5(), Guid = metafile.GetMD5(),
TargetAbi = _appVersion.ToString(), TargetAbi = _appVersion.ToString(),
MaxAbi = _nextVersion.ToString(),
Version = version.ToString() Version = version.ToString()
}; };
@ -678,11 +681,13 @@ namespace Emby.Server.Implementations
continue; continue;
} }
if (manifest.Status != PluginStatus.DeleteOnStartup)
{
manifest.Status = PluginStatus.DeleteOnStartup; manifest.Status = PluginStatus.DeleteOnStartup;
SaveManifest(manifest, entry.Path); SaveManifest(manifest, entry.Path);
} }
} }
}
// Only want plugin folders which have files. // Only want plugin folders which have files.
return versions.Where(p => p.DllFiles.Count != 0); return versions.Where(p => p.DllFiles.Count != 0);

View File

@ -93,8 +93,7 @@ namespace Emby.Server.Implementations.Updates
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;
_config = config; _config = config;
_zipClient = zipClient; _zipClient = zipClient;
_jsonSerializerOptions = JsonDefaults.GetOptions(); _jsonSerializerOptions = JsonDefaults.GetCamelCaseOptions();
_jsonSerializerOptions.PropertyNameCaseInsensitive = true;
_pluginManager = pluginManager; _pluginManager = pluginManager;
} }

View File

@ -47,7 +47,7 @@ namespace Jellyfin.Api.Controllers
{ {
_installationManager = installationManager; _installationManager = installationManager;
_pluginManager = pluginManager; _pluginManager = pluginManager;
_serializerOptions = JsonDefaults.GetOptions(); _serializerOptions = JsonDefaults.GetCamelCaseOptions();
_config = config; _config = config;
} }

View File

@ -56,6 +56,7 @@ namespace MediaBrowser.Common.Json
{ {
var options = GetOptions(); var options = GetOptions();
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.PropertyNameCaseInsensitive = true;
return options; return options;
} }

View File

@ -1,5 +1,3 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable SA1602 // Enumeration items should be documented
namespace MediaBrowser.Model.Plugins namespace MediaBrowser.Model.Plugins
{ {
/// <summary> /// <summary>
@ -7,12 +5,43 @@ namespace MediaBrowser.Model.Plugins
/// </summary> /// </summary>
public enum PluginStatus public enum PluginStatus
{ {
/// <summary>
/// This plugin requires a restart in order for it to load. This is a memory only status.
/// The actual status of the plugin after reload is present in the manifest.
/// eg. A disabled plugin will still be active until the next restart, and so will have a memory status of RestartRequired,
/// but a disk manifest status of Disabled.
/// </summary>
RestartRequired = 1, RestartRequired = 1,
/// <summary>
/// This plugin is currently running.
/// </summary>
Active = 0, Active = 0,
/// <summary>
/// This plugin has been marked as disabled.
/// </summary>
Disabled = -1, Disabled = -1,
/// <summary>
/// This plugin does not meet the TargetAbi / MaxAbi requirements.
/// </summary>
NotSupported = -2, NotSupported = -2,
/// <summary>
/// This plugin caused an error when instantiated. (Either DI loop, or exception)
/// </summary>
Malfunction = -3, Malfunction = -3,
/// <summary>
/// This plugin has been superceded by another version.
/// </summary>
Superceded = -4, Superceded = -4,
/// <summary>
/// An attempt to remove this plugin from disk will happen at every restart.
/// It will not be loaded, if unable to do so.
/// </summary>
DeleteOnStartup = -5 DeleteOnStartup = -5
} }
} }