diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
index 83e7b230df..4c668379c8 100644
--- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
+++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
@@ -13,19 +13,19 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Session;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.EntryPoints;
///
-/// A that notifies users when libraries are updated.
+/// A responsible for notifying users when libraries are updated.
///
-public sealed class LibraryChangedNotifier : IServerEntryPoint
+public sealed class LibraryChangedNotifier : IHostedService, IDisposable
{
private readonly ILibraryManager _libraryManager;
private readonly IServerConfigurationManager _configurationManager;
@@ -70,7 +70,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
}
///
- public Task RunAsync()
+ public Task StartAsync(CancellationToken cancellationToken)
{
_libraryManager.ItemAdded += OnLibraryItemAdded;
_libraryManager.ItemUpdated += OnLibraryItemUpdated;
@@ -83,6 +83,20 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
return Task.CompletedTask;
}
+ ///
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ _libraryManager.ItemAdded -= OnLibraryItemAdded;
+ _libraryManager.ItemUpdated -= OnLibraryItemUpdated;
+ _libraryManager.ItemRemoved -= OnLibraryItemRemoved;
+
+ _providerManager.RefreshCompleted -= OnProviderRefreshCompleted;
+ _providerManager.RefreshStarted -= OnProviderRefreshStarted;
+ _providerManager.RefreshProgress -= OnProviderRefreshProgress;
+
+ return Task.CompletedTask;
+ }
+
private void OnProviderRefreshProgress(object? sender, GenericEventArgs> e)
{
var item = e.Argument.Item1;
@@ -137,9 +151,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
}
private void OnProviderRefreshStarted(object? sender, GenericEventArgs e)
- {
- OnProviderRefreshProgress(sender, new GenericEventArgs>(new Tuple(e.Argument, 0)));
- }
+ => OnProviderRefreshProgress(sender, new GenericEventArgs>(new Tuple(e.Argument, 0)));
private void OnProviderRefreshCompleted(object? sender, GenericEventArgs e)
{
@@ -342,7 +354,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
return item.SourceType == SourceType.Library;
}
- private IEnumerable GetTopParentIds(List items, List allUserRootChildren)
+ private static IEnumerable GetTopParentIds(List items, List allUserRootChildren)
{
var list = new List();
@@ -363,7 +375,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
return list.Distinct(StringComparer.Ordinal);
}
- private IEnumerable TranslatePhysicalItemToUserLibrary(T item, User user, bool includeIfNotFound = false)
+ private T[] TranslatePhysicalItemToUserLibrary(T item, User user, bool includeIfNotFound = false)
where T : BaseItem
{
// If the physical root changed, return the user root
@@ -384,18 +396,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
///
public void Dispose()
{
- _libraryManager.ItemAdded -= OnLibraryItemAdded;
- _libraryManager.ItemUpdated -= OnLibraryItemUpdated;
- _libraryManager.ItemRemoved -= OnLibraryItemRemoved;
-
- _providerManager.RefreshCompleted -= OnProviderRefreshCompleted;
- _providerManager.RefreshStarted -= OnProviderRefreshStarted;
- _providerManager.RefreshProgress -= OnProviderRefreshProgress;
-
- if (_libraryUpdateTimer is not null)
- {
- _libraryUpdateTimer.Dispose();
- _libraryUpdateTimer = null;
- }
+ _libraryUpdateTimer?.Dispose();
+ _libraryUpdateTimer = null;
}
}
diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs
index 7cf7d75da0..bb5513f865 100644
--- a/Jellyfin.Server/Startup.cs
+++ b/Jellyfin.Server/Startup.cs
@@ -4,6 +4,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
+using Emby.Server.Implementations.EntryPoints;
using Jellyfin.Api.Middleware;
using Jellyfin.LiveTv.Extensions;
using Jellyfin.MediaEncoding.Hls.Extensions;
@@ -126,6 +127,7 @@ namespace Jellyfin.Server
services.AddHostedService();
services.AddHostedService();
+ services.AddHostedService();
}
///