using ErsatzTV.Core.Domain; using ErsatzTV.FFmpeg.State; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Streaming.Graphics; namespace ErsatzTV.Application.Channels; /// /// #732: the On Now / Next overlay is a default rather than an opt-in, so every newly created channel /// gets the built-in element attached. /// /// /// This lives in one place because there is more than one channel-creation path and they diverged /// once already: CreateChannelHandler had it and CreateChannelFromLineupHandler -- the /// SPA's primary "Add Channel" flow, and the one Auto-Tune bulk-creates through -- did not. Any new /// site that persists a Channel must call this. The third site, DbInitializer's default /// channel, needs no call: it runs before AttachOnNowNextByDefault in the same startup, so the /// backfill covers it. /// public static class ChannelGraphicsDefaults { public static async Task Attach(TvContext dbContext, Channel channel, CancellationToken cancellationToken) { // HLS Direct is skipped because ErsatzTV is not transcoding there -- there is no frame // pipeline to draw into, and the editor disables the toggle for the same reason. Identity is // the element's filename, never its user-editable Name (the #67 lesson). if (channel.StreamingMode is StreamingMode.HttpLiveStreamingDirect) { return; } Option maybeElementId = await GraphicsElementSeeder.GetBuiltInElementId(dbContext, cancellationToken); foreach (int elementId in maybeElementId) { // Add rather than assign: a future create path that carries graphics ids would otherwise // be silently discarded here. channel.ChannelGraphicsElements ??= []; channel.ChannelGraphicsElements.Add(new ChannelGraphicsElement { GraphicsElementId = elementId }); } } }