using System;
using System.Collections.Generic;
using System.Globalization;
using Jellyfin.Plugin.JRay.Configuration;
using Jellyfin.Plugin.JRay.Services;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.JRay;
///
/// The main plugin.
///
public class Plugin : BasePlugin, IHasWebPages
{
private readonly ILogger _logger;
private readonly bool _usingFileTransformation;
///
/// Initializes a new instance of the class.
///
/// Instance of the interface.
/// Instance of the interface.
/// The logger.
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogger logger)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
_logger = logger;
// The File Transformation plugin rewrites index.html as it is served.
// Registration is unconditional: the transformation itself checks
// EnableOverlay at request time, so toggling the setting takes effect
// without re-registering.
_usingFileTransformation = FileTransformationRegistration.TryRegister(_logger);
if (!_usingFileTransformation)
{
_logger.LogWarning(
"JRay: the pause overlay is disabled because the File Transformation plugin " +
"is not available. Install it from " +
"https://github.com/IAmParadox27/jellyfin-plugin-file-transformation. " +
"All other JRay features are unaffected.");
}
// JRay never injects into index.html. This only ever *removes* a patch
// left by an earlier version of JRay, identified by its own marker —
// see SPEC.md JR-021/JR-022.
WebClientPatchService.RemoveLegacyPatch(ApplicationPaths, _logger);
}
///
public override string Name => "JRay";
///
public override Guid Id => Guid.Parse("96a22d9d-23fd-49bb-8970-5e153817d223");
///
/// Gets the current plugin instance.
///
public static Plugin? Instance { get; private set; }
///
/// Gets a value indicating whether the pause overlay should currently be
/// served. Read by the File Transformation callback at request time, so
/// toggling the setting takes effect without re-registering.
///
internal static bool OverlayEnabled => Instance?.Configuration.EnableOverlay ?? false;
///
/// Gets a value indicating whether the File Transformation plugin was found
/// at startup. When it was not, the overlay is disabled and every other JRay
/// feature continues to work.
///
internal static bool FileTransformationAvailable => Instance?._usingFileTransformation ?? false;
///
public IEnumerable GetPages()
{
return
[
new PluginPageInfo
{
Name = Name,
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
}
];
}
}