Skip to content

Commit

Permalink
Merge pull request #5010 from BaronGreenback/Remove_IPluginConfigurat…
Browse files Browse the repository at this point in the history
…ionPage

Removal of IPluginConfigurationPage
  • Loading branch information
dkanada committed Feb 5, 2021
2 parents ad203d0 + a4e838f commit 86859a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 124 deletions.
58 changes: 8 additions & 50 deletions Jellyfin.Api/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,16 @@ public class DashboardController : BaseJellyfinApiController
/// Gets the configuration pages.
/// </summary>
/// <param name="enableInMainMenu">Whether to enable in the main menu.</param>
/// <param name="pageType">The <see cref="ConfigurationPageInfo"/>.</param>
/// <response code="200">ConfigurationPages returned.</response>
/// <response code="404">Server still loading.</response>
/// <returns>An <see cref="IEnumerable{ConfigurationPageInfo}"/> with infos about the plugins.</returns>
[HttpGet("web/ConfigurationPages")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<IEnumerable<ConfigurationPageInfo?>> GetConfigurationPages(
[FromQuery] bool? enableInMainMenu,
[FromQuery] ConfigurationPageType? pageType)
[FromQuery] bool? enableInMainMenu)
{
const string unavailableMessage = "The server is still loading. Please try again momentarily.";

var pages = _appHost.GetExports<IPluginConfigurationPage>().ToList();

if (pages == null)
{
return NotFound(unavailableMessage);
}

// Don't allow a failing plugin to fail them all
var configPages = pages.Select(p =>
{
try
{
return new ConfigurationPageInfo(p);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting plugin information from {Plugin}", p.GetType().Name);
return null;
}
})
.Where(i => i != null)
.ToList();

configPages.AddRange(_pluginManager.Plugins.SelectMany(GetConfigPages));

if (pageType.HasValue)
{
configPages = configPages.Where(p => p!.ConfigurationPageType == pageType).ToList();
}
var configPages = _pluginManager.Plugins.SelectMany(GetConfigPages).ToList();

if (enableInMainMenu.HasValue)
{
Expand Down Expand Up @@ -121,24 +89,14 @@ public ActionResult GetDashboardConfigurationPage([FromQuery] string? name)
var isJs = false;
var isTemplate = false;

var page = _appHost.GetExports<IPluginConfigurationPage>().FirstOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
if (page != null)
{
plugin = page.Plugin;
stream = page.GetHtmlStream();
}

if (plugin == null)
var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, name, StringComparison.OrdinalIgnoreCase));
if (altPage != null)
{
var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, name, StringComparison.OrdinalIgnoreCase));
if (altPage != null)
{
plugin = altPage.Item2;
stream = plugin.GetType().Assembly.GetManifestResourceStream(altPage.Item1.EmbeddedResourcePath);
plugin = altPage.Item2;
stream = plugin.GetType().Assembly.GetManifestResourceStream(altPage.Item1.EmbeddedResourcePath);

isJs = string.Equals(Path.GetExtension(altPage.Item1.EmbeddedResourcePath), ".js", StringComparison.OrdinalIgnoreCase);
isTemplate = altPage.Item1.EmbeddedResourcePath.EndsWith(".template.html", StringComparison.Ordinal);
}
isJs = string.Equals(Path.GetExtension(altPage.Item1.EmbeddedResourcePath), ".js", StringComparison.OrdinalIgnoreCase);
isTemplate = altPage.Item1.EmbeddedResourcePath.EndsWith(".template.html", StringComparison.Ordinal);
}

if (plugin != null && stream != null)
Expand Down
23 changes: 0 additions & 23 deletions Jellyfin.Api/Models/ConfigurationPageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ namespace Jellyfin.Api.Models
/// </summary>
public class ConfigurationPageInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationPageInfo"/> class.
/// </summary>
/// <param name="page">Instance of <see cref="IPluginConfigurationPage"/> interface.</param>
public ConfigurationPageInfo(IPluginConfigurationPage page)
{
Name = page.Name;

ConfigurationPageType = page.ConfigurationPageType;

if (page.Plugin != null)
{
DisplayName = page.Plugin.Name;
PluginId = page.Plugin.Id;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationPageInfo"/> class.
/// </summary>
Expand Down Expand Up @@ -68,12 +51,6 @@ public ConfigurationPageInfo(IPlugin? plugin, PluginPageInfo page)
/// </summary>
public string? DisplayName { get; set; }

/// <summary>
/// Gets or sets the type of the configuration page.
/// </summary>
/// <value>The type of the configuration page.</value>
public ConfigurationPageType ConfigurationPageType { get; set; }

/// <summary>
/// Gets or sets the plugin id.
/// </summary>
Expand Down
51 changes: 0 additions & 51 deletions MediaBrowser.Controller/Plugins/IPluginConfigurationPage.cs

This file was deleted.

0 comments on commit 86859a3

Please sign in to comment.