«Pagina iniziale» solo finché Alberto guida, e la vista che non si blocca (#52)

Una verifica indipendente di 654076d ha trovato tre punti deboli.

- «Pagina iniziale» guardava il permesso di guida una volta sola, prima di
  aspettare fino a 15 s la fine della sessione e 15 s il turno della pagina
  (che poi prendeva comunque). Se nel frattempo Alberto chiudeva la finestra,
  Febe navigava senza permesso e fuori dal Governatore (regole 7 e 8). Ora la
  pressione vale finché dura il permesso di chi l'ha premuta: la finestra di
  Windows passa un gettone che si annulla con il suo permesso, la vista remota
  quello della propria vita. Con il turno della pagina in mano la connessione
  guarda di nuovo che Alberto guidi ancora; senza turno rinuncia invece di
  prendere la pagina a un passo della ricerca. L'attesa del turno è
  BrowserConnectionService.PageTurnWait (15 s, le prove la accorciano).
- Nella vista remota «Pagina iniziale» aspettava dentro il ciclo di ricezione:
  la vista restava ferma fino a mezzo minuto e poi riversava clic e tasti sulla
  pagina nuova. Ora la pressione corre a parte, una per volta, e intanto clic,
  tasti, «Indietro» e «Ricarica» si scartano.
- Repaint chiedeva un ridisegno sincrono (RDW_UPDATENOW) a finestre figlie del
  processo del browser di WebView2: uno bloccato avrebbe fermato il thread
  dell'interfaccia. Ora si chiede solo di ridisegnare.

Prove nuove, che senza le correzioni non passano: la pressione dimenticata se
Alberto lascia il browser, quella che finisce con il permesso di chi l'ha
premuta, la pagina mai tolta a un passo della ricerca, la vista che non si
blocca e scarta l'input; su Windows con WebView2 vero, il gettone che si
annulla quando la finestra si chiude. PROTOCOLLO.md, la guida e decisioni.md
dicono il comportamento nuovo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-16 13:53:29 +01:00
1 parent 654076d280
commit 2bbad2e9b7
12 files changed
+340 -24

No files matched your search

+74 -9
View File
@@ -182,6 +182,7 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
private readonly RemoteViewSession _session;
private readonly Func<CancellationToken, Task>? _openStartPage;
private readonly ScreencastWatchdog? _watchdog;
private readonly IBrowserLog _log;
private readonly Lock _gate = new();
private readonly Queue<RemoteViewMeta> _meta = new();
private readonly SemaphoreSlim _signal = new(0, int.MaxValue);
@@ -198,6 +199,8 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
private int _height;
private int _disposed;
private bool _used;
private int _startPagePending;
private Task _startPage = Task.CompletedTask;
public BrowserRemoteViewConnection(BrowserRemoteViewHost owner, IFebeBrowser browser, BrowserUseTracker tracker, IClock clock, IClock browserClock, IBrowserLog log, Func<CancellationToken, Task>? openStartPage, ScreencastWatchdog? watchdog)
{
@@ -207,6 +210,7 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
_clock = clock;
_openStartPage = openStartPage;
_watchdog = watchdog;
_log = log;
// A real log (issue #52): the starts, restarts and silences of the frames reach the registro.
_session = new RemoteViewSession(browser.Cdp, browser.UserDriving, log, browserClock);
@@ -216,6 +220,21 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
private ICdpSession Cdp => _browser.Cdp;
/// <summary>True while a «Pagina iniziale» waits or loads: the input of the view is dropped meanwhile.</summary>
internal bool StartPagePending => Volatile.Read(ref _startPagePending) != 0;
/// <summary>The last «Pagina iniziale» of this view (a completed task before the first): tests wait on it.</summary>
internal Task StartPageOpening
{
get
{
lock (_gate)
{
return _startPage;
}
}
}
public async Task StartAsync(int width, int height, CancellationToken ct)
{
_width = width;
@@ -281,9 +300,11 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
public Task MouseAsync(RemoteViewMouse input, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(input);
if (_session.Screencast.LastFrame is null)
if (_session.Screencast.LastFrame is null || StartPagePending)
{
return Task.CompletedTask; // no frame yet: nothing on screen to point at
// No frame yet: nothing on screen to point at. «Pagina iniziale» in progress: a click would land on the page
// about to go, or on the start page while it loads.
return Task.CompletedTask;
}
MarkUsed();
@@ -307,6 +328,11 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
public Task KeyAsync(RemoteViewKey input, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(input);
if (StartPagePending)
{
return Task.CompletedTask; // as for the mouse: not typed into a page about to change
}
MarkUsed();
if (input.Action == RemoteViewKeyAction.Char)
{
@@ -321,16 +347,15 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
MarkUsed();
if (action == RemoteViewNavigation.Home)
{
// Alberto's own navigation (rule 7), done by the connection: like the start page opened from the rest page,
// it waits for the engine's session to end and takes the page's turn first.
if (_openStartPage is { } open)
{
await open(ct).ConfigureAwait(false);
}
OpenStartPage();
return;
}
if (StartPagePending)
{
return; // the start page is about to replace the page anyway
}
string? target;
lock (_gate)
{
@@ -366,6 +391,46 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
await _session.NavigateAsync(target, ct).ConfigureAwait(false);
}
/// <summary>
/// «Pagina iniziale»: Alberto's own navigation (rule 7), done by the connection — like the start page opened from the
/// rest page, it waits for the engine's session to end and takes the page's turn first, up to half a minute. So it runs
/// beside the view, not in its receive loop (the view would freeze meanwhile), for as long as the view and its lease
/// last; one at a time, and until it is done the view's input is dropped.
/// </summary>
private void OpenStartPage()
{
if (_openStartPage is not { } open || Interlocked.CompareExchange(ref _startPagePending, 1, 0) != 0)
{
return;
}
var task = Task.Run(() => OpenStartPageAsync(open), CancellationToken.None);
lock (_gate)
{
_startPage = task;
}
}
private async Task OpenStartPageAsync(Func<CancellationToken, Task> open)
{
try
{
await open(_ended.Token).ConfigureAwait(false);
}
catch (OperationCanceledException) when (_ended.IsCancellationRequested)
{
// The view closed first: its lease is gone, the page is the engine's.
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
_log.Write(BrowserLogLevel.Warning, $"«Pagina iniziale» non aperta ({ex.GetType().Name}).");
}
finally
{
Volatile.Write(ref _startPagePending, 0);
}
}
/// <summary>Ends the view from the server side (another tab, shutdown): the page is told why.</summary>
public async Task EndAsync(RemoteViewEnd reason)
{