feature: Phase 18.6 Track A — public Settings menu + streaming-quality toggle
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using DeepDrftPublic.Client.Common;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace DeepDrftPublic.Client.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Client-side runtime writer for public-site settings (Phase 18 wave 18.6), the analogue of
|
||||
/// <see cref="DarkModeCookieService"/>. Reads the current preference off the in-memory
|
||||
/// <see cref="PublicSiteSettings"/> (already seeded at prerender and bridged into WASM), and writes a
|
||||
/// 365-day cookie via <c>document.cookie</c> interop when the listener changes it in the Settings menu —
|
||||
/// the same durable-truth seam dark mode uses, so the choice survives the session and seeds the next visit's
|
||||
/// prerender (no flash).
|
||||
/// </summary>
|
||||
public class SettingsCookieService(PublicSiteSettings settings, IJSRuntime js) : SettingsServiceBase
|
||||
{
|
||||
private const int ExpiryDays = 365;
|
||||
|
||||
public StreamQuality GetStreamQuality() => settings.StreamQuality;
|
||||
|
||||
public async ValueTask SetStreamQualityAsync(StreamQuality quality)
|
||||
{
|
||||
if (settings.StreamQuality == quality) return;
|
||||
|
||||
await WriteCookieAsync(StreamQualityCookieName, FormatStreamQuality(quality));
|
||||
settings.StreamQuality = quality;
|
||||
}
|
||||
|
||||
private async ValueTask WriteCookieAsync(string name, string value)
|
||||
{
|
||||
var expires = DateTime.UtcNow.AddDays(ExpiryDays).ToString("R");
|
||||
await js.InvokeVoidAsync("eval",
|
||||
$"document.cookie = '{name}={value}; expires={expires}; path=/; SameSite=Lax'");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user