Richiesta di Alberto (#59): decidere cosa scaricare prima, una Dashboard compatta come pagina iniziale da guardare mentre il motore lavora, e le miniature di ciò che è arrivato. - Dashboard (§7.9, §10.2): /dashboard è la pagina iniziale e la prima voce della barra; /, /attivita, «Ho finito» del browser, il riquadro di stato e il ritorno dopo l'accesso portano lì. In alto l'anteprima del browser sempre visibile, chiesta ogni secondo mentre il motore lavora (LiveBrowserPreview cattura al più un fotogramma al secondo), accanto cosa sta facendo e i quattro tetti; poi la striscia più bassa, la cronologia con le miniature e la coda ridotta alle prime righe con «Mostra tutta». Sotto i 1000 px una colonna sola. - Miniature della cronologia: /api/activity/arrived dà gli elementi che una ricetta ha salvato (account, inizio e fine della ricetta), chiesti solo quando la riga entra in vista, al più otto con «+N». Un clic apre un'anteprima leggera con foto o video senza audio, frecce fra i file della riga, Esc, «Apri nella Libreria» e «Apri l'account». - «Cosa scaricare prima» (§7.2, §6.5): ordine generale dei tipi in Impostazioni → Limiti e comportamento (trascinare, «Su» e «Giù», nota sulle storie che scadono), predefinito storie, evidenza, post, reel, taggati. Dopo il giro, il lavoro dovuto si estrae con il peso dell'account per il peso del tipo (16, 8, 4, 2, 1): pesa, non rende fisso. La coda dei file segue lo stesso ordine. - Prove: DownloadOrderTests (ordine, pesi, coda, motore con seme fisso: il primo tipo viene più spesso ma non sempre, il giro resta primo, un tipo senza lavoro non si visita), DashboardApiTests, una prova dell'interfaccia per / e /attivita. Non ancora fatto: ordine per account e segno del reel (serve una migrazione da concordare con E1), «Raggruppa i post» / «Tutte le foto», confronto con i mockup, revisione del resto della guida che nomina ancora Attività. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using Febe.Browser.Cdp;
|
|
using Febe.Browser.RemoteView;
|
|
using Febe.Core.Abstractions;
|
|
using Febe.Web.Engine;
|
|
|
|
namespace Febe.App;
|
|
|
|
/// <summary>
|
|
/// Preview of the browser for the Dashboard (spec §7.9, mockup 06): one still frame taken with Page.captureScreenshot
|
|
/// when the page asks, at most one a second however many pages ask. Reading what the browser shows is not an action
|
|
/// toward the site. On the empty rest page there is nothing to show. The same in both shells.
|
|
/// </summary>
|
|
public sealed class LiveBrowserPreview(IFebeBrowser browser, IClock clock) : IBrowserPreview
|
|
{
|
|
private static readonly TimeSpan MinimumAge = TimeSpan.FromSeconds(1);
|
|
private readonly SemaphoreSlim _gate = new(1, 1);
|
|
private BrowserFrame? _last;
|
|
|
|
public async Task<BrowserFrame?> GetLatestAsync(CancellationToken ct)
|
|
{
|
|
if (!browser.IsAvailable)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
await _gate.WaitAsync(ct).ConfigureAwait(false);
|
|
try
|
|
{
|
|
var now = clock.Now;
|
|
if (_last is { } cached && now - cached.At < MinimumAge)
|
|
{
|
|
return cached;
|
|
}
|
|
|
|
var url = await browser.Cdp.GetMainFrameUrlAsync(ct).ConfigureAwait(false);
|
|
if (string.IsNullOrEmpty(url) || url.StartsWith("about:", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_last = null;
|
|
return null;
|
|
}
|
|
|
|
var jpeg = await PagePreview.CaptureAsync(browser.Cdp, ct: ct).ConfigureAwait(false);
|
|
_last = new BrowserFrame(jpeg, Addresses.WithoutQuery(url), now);
|
|
return _last;
|
|
}
|
|
catch (Exception ex) when (ex is CdpDisconnectedException or BrowserUnavailableException or CdpCommandException or TimeoutException or KeyNotFoundException or InvalidOperationException)
|
|
{
|
|
return null;
|
|
}
|
|
finally
|
|
{
|
|
_gate.Release();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Addresses as Febe may show them.</summary>
|
|
public static class Addresses
|
|
{
|
|
/// <summary>The address without query string or fragment (they may carry tokens).</summary>
|
|
public static string WithoutQuery(string url)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(url);
|
|
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
|
{
|
|
var cut = url.IndexOfAny(['?', '#']);
|
|
return cut < 0 ? url : url[..cut];
|
|
}
|
|
|
|
return uri.Scheme is "http" or "https" ? uri.GetLeftPart(UriPartial.Path) : uri.GetLeftPart(UriPartial.Scheme) + uri.AbsolutePath;
|
|
}
|
|
}
|