Files
LlamaCasty/ViewModels/MainViewModel.Alerts.cs
T
gramps 72cb3ad55a feat(stream): retry a dropped push instead of ending the session (TASK 32·1)
A dead encoder used to run the whole stop path, so a one-second blip ended the broadcast. Now a dropped
push is relaunched against the same ingest while the broadcast is still alive.

- `Services/StreamRetryPolicy.cs` — immediate, +1 s, +2 s, +3 s. Minimum waits on purpose (creator
  ruling): YouTube's grace is short, so every second not pushing is grace spent.
- `Services/StreamRecovery.cs` — the loop, with the audio pipe recreated before every attempt (its
  server is single-instance and unusable after the old client dies, so a naive relaunch fails on a
  missing input). After a push comes up it asks the API whether the broadcast survived: "complete"
  ends recovery as `BroadcastComplete` instead of showing a live sign over a dead stream; an API
  hiccup counts as recovered rather than ending a healthy session.
- `FramePump.EncoderFailed` — a dead push is recoverable; a compositor fault still goes through
  `Failed` and ends the session, because retrying it would loop.
- `MainViewModel.Recovery.cs` — wires the steps, reports each episode into the left panel alert stack
  (one row per episode, updated in place, log range painted), and cancels on Stop.
- Alert stack polish: a rule and a gap now separate the stack from the scene layers (they read as one
  list before), and the licence indicator uses the creator's wording — `STEAM ID NOT PRESENT` /
  `Steam ID Limit: 30fps` / `Click for More Info`, becoming `STEAM ID PRESENT` / `60fps` with a close
  control once owned.

Tests: `StreamRecoveryTests` (schedule, recover on attempt 2 with the pipe restarted each time,
complete-broadcast honesty, unknown liveness, give-up, cancel, audio-restart fault),
`FramePumpTests` now pin that process death raises `EncoderFailed` and not `Failed`.
FAST gate: 538 passed (one documented pre-existing audio failure), 0 warnings.
2026-11-05 12:09:38 -08:00

142 lines
5.5 KiB
C#

using System.Collections.ObjectModel;
using System.Linq;
using ytLive.Helpers;
using ytLive.Models;
namespace ytLive.ViewModels;
/// <summary>
/// The left panel's alert stack (creator design, 2026-11-05): standing state on top, transient events
/// beneath it, newest first, pushing the panel's content down. Only red rows belong here — the panel
/// is where "something needs you" lives, so it never fills with chatter.
/// <para><b>Row 1 is the Steam licence indicator</b> and nothing displaces it. It is pinned while
/// higher output tiers are unavailable, and becomes dismissible — permanently — once ownership is
/// verified. If ownership is later lost, it comes back as a pinned indicator, because that is a change
/// of state rather than a preference.</para>
/// </summary>
public partial class MainViewModel
{
private const string SteamLicenceAlertId = "steam-licence";
private readonly ObservableCollection<AttentionAlert> _attentionAlerts = new();
private bool _steamLicenceDismissed;
public ObservableCollection<AttentionAlert> AttentionAlerts => _attentionAlerts;
public bool HasAttentionAlerts => _attentionAlerts.Count > 0;
public RelayCommand<AttentionAlert> DismissAlertCommand => new(DismissAlert);
public RelayCommand<AttentionAlert> ActivateAlertCommand => new(ActivateAlert);
/// <summary>The licence indicator's text (creator wording, 2026-11-05): the limit this build runs
/// at, plus where to find out why. Not a warning — the resolution picker explains the detail, and
/// clicking the row opens About.</summary>
private string SteamLicenceText()
{
var entitled = 30;
if (QualityOptions.Length > 0)
{
entitled = QualityOptions
.Where(option => HasProOutput || !option.RequiresPro)
.Select(option => option.Fps)
.DefaultIfEmpty(30)
.Max();
}
return $"Steam ID Limit: {entitled}fps\nClick for More Info";
}
private string SteamLicenceLabel() => IsAppOwned ? "STEAM ID PRESENT" : "STEAM ID NOT PRESENT";
/// <summary>Recomputes row 1 in place. Called at startup and whenever ownership changes.</summary>
private void RefreshSteamLicenceAlert()
{
var existing = _attentionAlerts.FirstOrDefault(alert => alert.Id == SteamLicenceAlertId);
var hidden = IsAppOwned && _steamLicenceDismissed;
if (hidden)
{
if (existing != null) _attentionAlerts.Remove(existing);
RaiseAttentionChanged();
return;
}
var alert = new AttentionAlert(
SteamLicenceAlertId,
SteamLicenceLabel(),
SteamLicenceText(),
IsPinned: !IsAppOwned,
AttentionAlertAction.About);
var index = existing == null ? -1 : _attentionAlerts.IndexOf(existing);
if (index < 0) _attentionAlerts.Insert(0, alert);
else _attentionAlerts[index] = alert; // same row, updated state
RaiseAttentionChanged();
}
/// <summary>Pushes an event alert. Newest sits directly under the licence indicator; older ones
/// stack beneath, so the newest is the one nearest the eye.</summary>
private AttentionAlert? PushAttentionAlert(string id, string label, string text, long logFrom, long logTo)
{
var alert = new AttentionAlert(id, label, text, IsPinned: false, AttentionAlertAction.Logs, logFrom, logTo);
var insertAt = _attentionAlerts.Count(alert => alert.Id == SteamLicenceAlertId);
var existing = _attentionAlerts.FirstOrDefault(candidate => candidate.Id == id);
if (existing != null)
{
// Same event advancing (reconnecting attempt 2 → 3): update the row, never duplicate it.
_attentionAlerts[_attentionAlerts.IndexOf(existing)] = alert;
}
else
{
_attentionAlerts.Insert(insertAt, alert);
}
RaiseAttentionChanged();
return alert;
}
/// <summary>Test seam: pushes an event row without a stream session behind it.</summary>
internal AttentionAlert? PushAttentionAlertForTest(string id, string label, string text, long logFrom, long logTo)
=> PushAttentionAlert(id, label, text, logFrom, logTo);
private void RemoveAttentionAlert(string id)
{
var existing = _attentionAlerts.FirstOrDefault(alert => alert.Id == id);
if (existing == null) return;
_attentionAlerts.Remove(existing);
RaiseAttentionChanged();
}
private void DismissAlert(AttentionAlert? alert)
{
if (alert == null || alert.IsPinned) return;
if (alert.Id == SteamLicenceAlertId)
{
// Permanent for this profile: the creator said "I have seen it". Only honoured while
// ownership holds — RefreshSteamLicenceAlert ignores it when Steam stops confirming.
_steamLicenceDismissed = true;
_layoutStore.SaveSteamLicenceIndicatorDismissed(true);
}
RemoveAttentionAlert(alert.Id);
}
private void ActivateAlert(AttentionAlert? alert)
{
if (alert == null) return;
if (alert.Action == AttentionAlertAction.About)
{
ShowAbout();
return;
}
// Event alert: open the log and paint this event's lines, so the alert is an entry point to
// the detail rather than a dead end.
HighlightLogRange(alert.LogFrom, alert.LogTo);
SelectLogsTab(true);
}
private void RaiseAttentionChanged() => OnPropertyChanged(nameof(HasAttentionAlerts));
}