Skip to content

Commit

Permalink
Use DI for ILiveTvService
Browse files Browse the repository at this point in the history
  • Loading branch information
barronpm authored and KrzaQ committed Feb 13, 2024
1 parent cf904d8 commit 269d4ad
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
2 changes: 0 additions & 2 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,6 @@ private void FindParts()
GetExports<IMetadataSaver>(),
GetExports<IExternalId>());

Resolve<ILiveTvManager>().AddParts(GetExports<ILiveTvService>());

Resolve<IMediaSourceManager>().AddParts(GetExports<IMediaSourceProvider>());
}

Expand Down
6 changes: 0 additions & 6 deletions MediaBrowser.Controller/LiveTv/ILiveTvManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ public interface ILiveTvManager
/// <returns>Task.</returns>
Task CancelSeriesTimer(string id);

/// <summary>
/// Adds the parts.
/// </summary>
/// <param name="services">The services.</param>
void AddParts(IEnumerable<ILiveTvService> services);

/// <summary>
/// Gets the timer.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static void AddLiveTvServices(this IServiceCollection services)
services.AddSingleton<ITunerHostManager, TunerHostManager>();
services.AddSingleton<IGuideManager, GuideManager>();

services.AddSingleton<ILiveTvService, EmbyTV.EmbyTV>();
services.AddSingleton<ITunerHost, HdHomerunHost>();
services.AddSingleton<ITunerHost, M3UTunerHost>();
services.AddSingleton<IListingsProvider, SchedulesDirect>();
Expand Down
24 changes: 7 additions & 17 deletions src/Jellyfin.LiveTv/LiveTvManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ public class LiveTvManager : ILiveTvManager
private readonly ILocalizationManager _localization;
private readonly IChannelManager _channelManager;
private readonly LiveTvDtoService _tvDtoService;
private readonly ILiveTvService[] _services;
private readonly IListingsProvider[] _listingProviders;

private ILiveTvService[] _services = Array.Empty<ILiveTvService>();

public LiveTvManager(
IServerConfigurationManager config,
ILogger<LiveTvManager> logger,
Expand All @@ -63,6 +62,7 @@ public class LiveTvManager : ILiveTvManager
ILocalizationManager localization,
IChannelManager channelManager,
LiveTvDtoService liveTvDtoService,
IEnumerable<ILiveTvService> services,
IEnumerable<IListingsProvider> listingProviders)
{
_config = config;
Expand All @@ -75,7 +75,12 @@ public class LiveTvManager : ILiveTvManager
_userDataManager = userDataManager;
_channelManager = channelManager;
_tvDtoService = liveTvDtoService;
_services = services.ToArray();
_listingProviders = listingProviders.ToArray();

var defaultService = _services.OfType<EmbyTV.EmbyTV>().First();
defaultService.TimerCreated += OnEmbyTvTimerCreated;
defaultService.TimerCancelled += OnEmbyTvTimerCancelled;
}

public event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCancelled;
Expand All @@ -99,21 +104,6 @@ public string GetEmbyTvActiveRecordingPath(string id)
return EmbyTV.EmbyTV.Current.GetActiveRecordingPath(id);
}

/// <inheritdoc />
public void AddParts(IEnumerable<ILiveTvService> services)
{
_services = services.ToArray();

foreach (var service in _services)
{
if (service is EmbyTV.EmbyTV embyTv)
{
embyTv.TimerCreated += OnEmbyTvTimerCreated;
embyTv.TimerCancelled += OnEmbyTvTimerCancelled;
}
}
}

private void OnEmbyTvTimerCancelled(object sender, GenericEventArgs<string> e)
{
var timerId = e.Argument;
Expand Down

0 comments on commit 269d4ad

Please sign in to comment.