Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e33cb8fb7 | ||
|
|
15d6f98427 | ||
|
|
3b1d0982e5 | ||
|
|
737e510a6c | ||
|
|
fbd77e56fd |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,4 +4,5 @@ obj/
|
||||
.idea/
|
||||
artifacts
|
||||
|
||||
build.yaml
|
||||
RELEASE_GUIDE.md
|
||||
@@ -21,7 +21,7 @@ public class SeasonalsController : ControllerBase
|
||||
[Produces("application/json")]
|
||||
public ActionResult<object> GetConfig()
|
||||
{
|
||||
return Plugin.Instance?.Configuration ?? new object();
|
||||
return SeasonalsPlugin.Instance?.Configuration ?? new object();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,6 +12,7 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||
/// </summary>
|
||||
public PluginConfiguration()
|
||||
{
|
||||
IsEnabled = true;
|
||||
SelectedSeason = "none";
|
||||
AutomateSeasonSelection = true;
|
||||
|
||||
@@ -27,6 +28,11 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||
Easter = new EasterOptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the plugin is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the selected season.
|
||||
/// </summary>
|
||||
|
||||
@@ -24,6 +24,13 @@
|
||||
<hr style="max-width: 800px; margin: 1em 0;">
|
||||
<br>
|
||||
<form id="SeasonalsConfigForm">
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="IsEnabled" name="IsEnabled" type="checkbox" is="emby-checkbox" />
|
||||
<span>Enable Seasonals</span>
|
||||
</label>
|
||||
<div class="fieldDescription">Enable or disable the entire plugin functionality.</div>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="AutomateSeasonSelection" name="AutomateSeasonSelection" type="checkbox" is="emby-checkbox" />
|
||||
@@ -520,6 +527,7 @@
|
||||
.addEventListener('pageshow', function() {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(SeasonalsConfig.pluginUniqueId).then(function (config) {
|
||||
document.querySelector('#IsEnabled').checked = config.IsEnabled;
|
||||
document.querySelector('#SelectedSeason').value = config.SelectedSeason;
|
||||
document.querySelector('#AutomateSeasonSelection').checked = config.AutomateSeasonSelection;
|
||||
|
||||
@@ -615,6 +623,7 @@
|
||||
.addEventListener('submit', function(e) {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(SeasonalsConfig.pluginUniqueId).then(function (config) {
|
||||
config.IsEnabled = document.querySelector('#IsEnabled').checked;
|
||||
config.SelectedSeason = document.querySelector('#SelectedSeason').value;
|
||||
config.AutomateSeasonSelection = document.querySelector('#AutomateSeasonSelection').checked;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<!-- <TreatWarningsAsErrors>false</TreatWarningsAsErrors> -->
|
||||
<Title>Jellyfin Seasonals Plugin</Title>
|
||||
<Authors>CodeDevMLH</Authors>
|
||||
<Version>1.3.4.0</Version>
|
||||
<Version>1.4.0.0</Version>
|
||||
<RepositoryUrl>https://github.com/CodeDevMLH/jellyfin-plugin-seasonals</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -83,26 +83,26 @@ public class ScriptInjector
|
||||
/// <summary>
|
||||
/// Removes the script tag from index.html.
|
||||
/// </summary>
|
||||
public void Remove()
|
||||
public bool Remove()
|
||||
{
|
||||
try
|
||||
{
|
||||
var webPath = GetWebPath();
|
||||
if (string.IsNullOrEmpty(webPath))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
var indexPath = Path.Combine(webPath, "index.html");
|
||||
if (!File.Exists(indexPath))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
var content = File.ReadAllText(indexPath);
|
||||
if (!content.Contains(ScriptTag, StringComparison.Ordinal))
|
||||
{
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Try to remove with newline first, then just the tag to ensure clean removal
|
||||
@@ -111,14 +111,17 @@ public class ScriptInjector
|
||||
|
||||
File.WriteAllText(indexPath, newContent);
|
||||
_logger.LogInformation("Successfully removed Seasonals script from index.html.");
|
||||
return true;
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
_logger.LogWarning("Permission denied when attempting to remove script from index.html.");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error removing Seasonals script.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ namespace Jellyfin.Plugin.Seasonals;
|
||||
/// <summary>
|
||||
/// The main plugin.
|
||||
/// </summary>
|
||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
public class SeasonalsPlugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
{
|
||||
private readonly ScriptInjector _scriptInjector;
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
||||
@@ -28,14 +29,49 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
||||
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
|
||||
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILoggerFactory loggerFactory)
|
||||
public SeasonalsPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILoggerFactory loggerFactory)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
Instance = this;
|
||||
_loggerFactory = loggerFactory;
|
||||
_scriptInjector = new ScriptInjector(applicationPaths, loggerFactory.CreateLogger<ScriptInjector>());
|
||||
if (!_scriptInjector.Inject())
|
||||
|
||||
if (Configuration.IsEnabled)
|
||||
{
|
||||
TryRegisterFallback(loggerFactory.CreateLogger("FileTransformationFallback"));
|
||||
if (!_scriptInjector.Inject())
|
||||
{
|
||||
TryRegisterFallback(loggerFactory.CreateLogger("FileTransformationFallback"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_scriptInjector.Remove()) {
|
||||
TryRemoveFallback(loggerFactory.CreateLogger("FileTransformationFallback"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void UpdateConfiguration(BasePluginConfiguration configuration)
|
||||
{
|
||||
var oldConfig = Configuration;
|
||||
base.UpdateConfiguration(configuration);
|
||||
|
||||
if (Configuration.IsEnabled != oldConfig.IsEnabled)
|
||||
{
|
||||
if (Configuration.IsEnabled)
|
||||
{
|
||||
if (!_scriptInjector.Inject())
|
||||
{
|
||||
TryRegisterFallback(_loggerFactory.CreateLogger("FileTransformationFallback"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_scriptInjector.Remove()) {
|
||||
TryRemoveFallback(_loggerFactory.CreateLogger("FileTransformationFallback"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +84,7 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
/// <summary>
|
||||
/// Gets the current plugin instance.
|
||||
/// </summary>
|
||||
public static Plugin? Instance { get; private set; }
|
||||
public static SeasonalsPlugin? Instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Callback method for FileTransformation plugin.
|
||||
@@ -68,10 +104,24 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
try
|
||||
{
|
||||
var html = originalContents;
|
||||
const string inject = "<script src=\"/Seasonals/Resources/seasonals.js\"></script>\n<body";
|
||||
const string scriptTag = "<script src=\"/Seasonals/Resources/seasonals.js\" defer></script>";
|
||||
// MARK: Remember me to remove legacy script tag support in future versions...
|
||||
const string legacyScriptTag = "<script src=\"/Seasonals/Resources/seasonals.js\"></script>";
|
||||
|
||||
if (Instance?.Configuration.IsEnabled != true)
|
||||
{
|
||||
// Remove script if present
|
||||
if (html.Contains("seasonals.js", StringComparison.Ordinal))
|
||||
{
|
||||
return html.Replace(scriptTag, "", StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(legacyScriptTag, "", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
if (!html.Contains("seasonals.js", StringComparison.Ordinal))
|
||||
{
|
||||
var inject = $"{scriptTag}\n<body";
|
||||
return html.Replace("<body", inject, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
@@ -133,6 +183,44 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
}
|
||||
}
|
||||
|
||||
private void TryRemoveFallback(ILogger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
var assembly = AssemblyLoadContext.All
|
||||
.SelectMany(x => x.Assemblies)
|
||||
.FirstOrDefault(x => x.FullName?.Contains(".FileTransformation") ?? false);
|
||||
|
||||
if (assembly == null)
|
||||
{
|
||||
logger.LogWarning("FileTransformation plugin not found. Fallback removal skipped.");
|
||||
return;
|
||||
}
|
||||
|
||||
var type = assembly.GetType("Jellyfin.Plugin.FileTransformation.PluginInterface");
|
||||
if (type == null)
|
||||
{
|
||||
logger.LogWarning("Jellyfin.Plugin.FileTransformation.PluginInterface not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var method = type.GetMethod("RemoveTransformation");
|
||||
if (method == null)
|
||||
{
|
||||
logger.LogWarning("RemoveTransformation method not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
Guid pluginId = Id is Guid g ? g : Guid.Parse(Id.ToString());
|
||||
method.Invoke(null, new object[] { pluginId });
|
||||
logger.LogInformation("Successfully unregistered fallback transformation via FileTransformation plugin.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error attempting to unregister fallback transformation.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PluginPageInfo> GetPages()
|
||||
{
|
||||
@@ -141,6 +229,7 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
new PluginPageInfo
|
||||
{
|
||||
Name = Name,
|
||||
EnableInMainMenu = true,
|
||||
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
|
||||
}
|
||||
};
|
||||
@@ -8,6 +8,14 @@
|
||||
"category": "General",
|
||||
"imageUrl": "https://git.mahom03-spacecloud.de/CodeDevMLH/Jellyfin-Seasonals-Plugin/raw/branch/main/logo.png",
|
||||
"versions": [
|
||||
{
|
||||
"version": "1.4.0.0",
|
||||
"changelog": "- settings linked directly in the main menu\n- renamed main plugin script\n- added enable/disable toggle for the entire plugin",
|
||||
"targetAbi": "10.11.0.0",
|
||||
"sourceUrl": "https://git.mahom03-spacecloud.de/CodeDevMLH/Jellyfin-Seasonals-Plugin/releases/download/v1.4.0.0/Jellyfin.Plugin.Seasonals.zip",
|
||||
"checksum": "205606075eec5f93d3da37efaecdeab5",
|
||||
"timestamp": "2025-12-28T19:11:04Z"
|
||||
},
|
||||
{
|
||||
"version": "1.3.4.0",
|
||||
"changelog": "- some fixes for js loading\n- adapted config page descriptions",
|
||||
|
||||
Reference in New Issue
Block a user