From 208d545cfefd5ce7a2092f4ac669e58cae115d37 Mon Sep 17 00:00:00 2001 From: Greenback Date: Tue, 15 Dec 2020 10:05:04 +0000 Subject: [PATCH] Changed as suggested. --- .../Plugins/PluginManager.cs | 27 ++++++++------- .../Updates/InstallationManager.cs | 3 +- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- MediaBrowser.Common/Json/JsonDefaults.cs | 1 + MediaBrowser.Model/Plugins/PluginStatus.cs | 33 +++++++++++++++++-- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index cf25ccf485..010d2829c4 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -53,9 +53,7 @@ namespace Emby.Server.Implementations _logger = loggerfactory.CreateLogger(); _pluginsPath = pluginsPath; _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion)); - _jsonOptions = JsonDefaults.GetOptions(); - _jsonOptions.PropertyNameCaseInsensitive = true; - _jsonOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + _jsonOptions = JsonDefaults.GetCamelCaseOptions(); _config = config; _appHost = appHost; _imagesPath = imagesPath; @@ -137,7 +135,8 @@ namespace Emby.Server.Implementations var plugin = GetPluginByType(pluginServiceRegistrator.Assembly.GetType()); if (plugin == null) { - throw new NullReferenceException(); + _logger.LogError("Unable to find plugin in assembly {Assembly}", pluginServiceRegistrator.Assembly.FullName); + continue; } CheckIfStillSuperceded(plugin); @@ -440,6 +439,7 @@ namespace Emby.Server.Implementations plugin.Instance = (IPlugin)instance; var manifest = plugin.Manifest; var pluginStr = plugin.Instance.Version.ToString(); + bool changed = false; if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal)) { // If a plugin without a manifest failed to load due to an external issue (eg config), @@ -447,10 +447,16 @@ namespace Emby.Server.Implementations manifest.Version = pluginStr; manifest.Name = plugin.Instance.Name; manifest.Description = plugin.Instance.Description; + changed = true; } + changed = changed || manifest.Status != PluginStatus.Active; manifest.Status = PluginStatus.Active; - SaveManifest(manifest, plugin.Path); + + if (changed) + { + SaveManifest(manifest, plugin.Path); + } } _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. - // 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 { Status = PluginStatus.RestartRequired, @@ -586,7 +590,6 @@ namespace Emby.Server.Implementations AutoUpdate = false, Guid = metafile.GetMD5(), TargetAbi = _appVersion.ToString(), - MaxAbi = _nextVersion.ToString(), Version = version.ToString() }; @@ -678,9 +681,11 @@ namespace Emby.Server.Implementations continue; } - manifest.Status = PluginStatus.DeleteOnStartup; - - SaveManifest(manifest, entry.Path); + if (manifest.Status != PluginStatus.DeleteOnStartup) + { + manifest.Status = PluginStatus.DeleteOnStartup; + SaveManifest(manifest, entry.Path); + } } } diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 75a9ca0801..b7bbbd3482 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -93,8 +93,7 @@ namespace Emby.Server.Implementations.Updates _httpClientFactory = httpClientFactory; _config = config; _zipClient = zipClient; - _jsonSerializerOptions = JsonDefaults.GetOptions(); - _jsonSerializerOptions.PropertyNameCaseInsensitive = true; + _jsonSerializerOptions = JsonDefaults.GetCamelCaseOptions(); _pluginManager = pluginManager; } diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index c84dc6a130..eb6b770d67 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -47,7 +47,7 @@ namespace Jellyfin.Api.Controllers { _installationManager = installationManager; _pluginManager = pluginManager; - _serializerOptions = JsonDefaults.GetOptions(); + _serializerOptions = JsonDefaults.GetCamelCaseOptions(); _config = config; } diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs index b76edd2bc7..50393b909a 100644 --- a/MediaBrowser.Common/Json/JsonDefaults.cs +++ b/MediaBrowser.Common/Json/JsonDefaults.cs @@ -56,6 +56,7 @@ namespace MediaBrowser.Common.Json { var options = GetOptions(); options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + options.PropertyNameCaseInsensitive = true; return options; } diff --git a/MediaBrowser.Model/Plugins/PluginStatus.cs b/MediaBrowser.Model/Plugins/PluginStatus.cs index a953206e89..2acc56811e 100644 --- a/MediaBrowser.Model/Plugins/PluginStatus.cs +++ b/MediaBrowser.Model/Plugins/PluginStatus.cs @@ -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 { /// @@ -7,12 +5,43 @@ namespace MediaBrowser.Model.Plugins /// public enum PluginStatus { + /// + /// 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. + /// RestartRequired = 1, + + /// + /// This plugin is currently running. + /// Active = 0, + + /// + /// This plugin has been marked as disabled. + /// Disabled = -1, + + /// + /// This plugin does not meet the TargetAbi / MaxAbi requirements. + /// NotSupported = -2, + + /// + /// This plugin caused an error when instantiated. (Either DI loop, or exception) + /// Malfunction = -3, + + /// + /// This plugin has been superceded by another version. + /// Superceded = -4, + + /// + /// An attempt to remove this plugin from disk will happen at every restart. + /// It will not be loaded, if unable to do so. + /// DeleteOnStartup = -5 } }