Docker: lasciare la pagina del browser copia la sessione (#36, S4b, risposta 1)
In Docker lasciare la pagina «Browser» o la vista remota di Collegamento mentre Alberto guida (un'altra pagina, la scheda chiusa, il collegamento perso) valeva «Annulla» e la sessione non si copiava. Ora è come chiudere la finestra del browser su Windows: `cancel` con `pageLeft` va a LeavePageAsync, la vista remota chiusa dalla sua pagina lo dice alla connessione, e se per 5 secondi non si apre un'altra vista né arriva un `begin` (una pagina ricaricata) il controllo del permesso copia la sessione con CopyOnLetGoAsync, solo da una pagina del sito che non sia di accesso o di verifica, poi rilascia il permesso e il motore rimette il browser a riposo. Il pulsante «Annulla» continua a non copiare; Windows non cambia. Prove nuove per la copia lasciando la pagina, la ricarica che non è lasciare, la pagina di accesso, la vista sostituita o chiusa da Febe; guida, protocollo e una riga in decisioni.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
537517b855
commit
2fc4b40c41
15 files changed
+312
-44
No files matched your search
@@ -43,8 +43,10 @@ namespace Febe.App;
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// With a saved session (issue #36, S4b) the session is copied at «Ho finito», and also when Alberto lets go of the
|
||||
/// browser without it: the window «Browser di Febe» closed on Windows (<see cref="CopyOnWindowClosedAsync"/>) and the
|
||||
/// lease of «Accedi» / «Usa il browser» ending by itself. Always before the page goes back to the engine, with the
|
||||
/// browser without it: the window «Browser di Febe» closed on Windows (<see cref="CopyOnWindowClosedAsync"/>), the page
|
||||
/// of the browser left in Docker (<see cref="LeavePageAsync"/>, <see cref="RemoteViewClosed"/>: after
|
||||
/// <see cref="PageLeaveGrace"/> without a view open again, answer of 25 November 2026) and the lease of «Accedi» /
|
||||
/// «Usa il browser» ending by itself. «Annulla» never copies. Always before the page goes back to the engine, with the
|
||||
/// same guarantees as «Ho finito» (the driving gate held, the page's turn), and only from a page of the site that is
|
||||
/// not a login or verification page. «Collegato» then also needs a readable saved session: without one the state is
|
||||
/// <see cref="ConnectionState.SessionCopyMissing"/> («Serve «Ho finito»») and the engine waits.
|
||||
@@ -64,6 +66,9 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
/// <summary>How often the cookie is looked at in the background (outside sessions it is the only way to notice).</summary>
|
||||
public static readonly TimeSpan BackgroundCheck = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>How the log names leaving the page of the browser in Docker (answer of 25 November 2026).</summary>
|
||||
private const string PageLeftText = "Pagina del browser lasciata";
|
||||
|
||||
private readonly IFebeBrowser _browser;
|
||||
private readonly IFebeStorage _storage;
|
||||
private readonly BrowserUseTracker _tracker;
|
||||
@@ -85,6 +90,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
private DateTimeOffset _checkedAt = DateTimeOffset.MinValue;
|
||||
private DateTimeOffset _lastCopyAt = DateTimeOffset.MinValue;
|
||||
private SessionCopyOutcome? _letGoCopy;
|
||||
private DateTimeOffset? _leftAt;
|
||||
|
||||
/// <param name="browser">The browser of Febe.</param>
|
||||
/// <param name="storage">The database (first connection, «Scollega»).</param>
|
||||
@@ -169,6 +175,14 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
/// </summary>
|
||||
public TimeSpan DrivingGrace { get; set; } = TimeSpan.FromMinutes(2);
|
||||
|
||||
/// <summary>
|
||||
/// How long after Alberto left the page of the browser in Docker (<see cref="LeavePageAsync"/>, or its remote view
|
||||
/// closed by the page: <see cref="RemoteViewClosed"/>) no view may open again before Febe takes it as letting go of
|
||||
/// the browser (answer of 25 November 2026, proposal of 5 seconds): a reload of the page opens its view again well
|
||||
/// before. Read at every look; tests shorten it.
|
||||
/// </summary>
|
||||
public TimeSpan PageLeaveGrace { get; set; } = TimeSpan.FromSeconds(5);
|
||||
|
||||
/// <summary>
|
||||
/// How long Alberto's page waits for its turn while a step of the profile search holds it (real time). Read at every
|
||||
/// wait; tests shorten it.
|
||||
@@ -273,6 +287,9 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
}
|
||||
|
||||
_lastDrivingSign = _clock.Now;
|
||||
|
||||
// Alberto is back (a reload of the page left a moment ago): not a letting go.
|
||||
_leftAt = null;
|
||||
}
|
||||
|
||||
_tracker.MarkUsed(_clock.Now);
|
||||
@@ -397,6 +414,52 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Docker (answer of 25 November 2026): the page of the browser was left without «Ho finito» or «Annulla». Nothing
|
||||
/// happens at once — a reload opens the page, «Usa il browser» and the view again within a moment. The watch of the
|
||||
/// lease lets go of the browser once, for <see cref="PageLeaveGrace"/> after this and after the last view closed, no
|
||||
/// view is open and no «Accedi» / «Usa il browser» came: the copy of the session as when the window is closed on
|
||||
/// Windows, then the lease ends and the page goes back to the engine (which puts it to rest).
|
||||
/// </summary>
|
||||
public Task LeavePageAsync(CancellationToken ct)
|
||||
{
|
||||
if (NoteLeft())
|
||||
{
|
||||
_log.Info("collegamento", $"Pagina del browser lasciata senza «Ho finito» né «Annulla»: se entro {ItalianText.Duration(PageLeaveGrace)} non torni al browser, Febe copia la sessione e il motore può riprendere.");
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Docker: a remote view was closed by its page (the page left, the tab closed, the link lost; not another view taking
|
||||
/// its place, nor Febe stopping). While the lease of «Accedi» / «Usa il browser» holds it counts as leaving the page
|
||||
/// (<see cref="LeavePageAsync"/>): the last view closed, the moment starts again from now.
|
||||
/// </summary>
|
||||
public void RemoteViewClosed()
|
||||
{
|
||||
// The browser gone: its view closed with it, Alberto did not leave (the page opens it again once it is back).
|
||||
if (_browser.IsAvailable)
|
||||
{
|
||||
NoteLeft();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Notes that Alberto may have left the browser; false without the lease of «Accedi» / «Usa il browser».</summary>
|
||||
private bool NoteLeft()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_lease is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_leftAt = _clock.Now;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<FinishResult> FinishAsync(CancellationToken ct)
|
||||
{
|
||||
await _commands.WaitAsync(ct).ConfigureAwait(false);
|
||||
@@ -718,9 +781,12 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
while (true)
|
||||
{
|
||||
var grace = DrivingGrace;
|
||||
var poll = TimeSpan.FromTicks(Math.Clamp(grace.Ticks / 8, TimeSpan.FromMilliseconds(20).Ticks, TimeSpan.FromSeconds(5).Ticks));
|
||||
var leaveGrace = PageLeaveGrace;
|
||||
var shortest = leaveGrace < grace ? leaveGrace : grace;
|
||||
var poll = TimeSpan.FromTicks(Math.Clamp(shortest.Ticks / 8, TimeSpan.FromMilliseconds(20).Ticks, TimeSpan.FromSeconds(5).Ticks));
|
||||
await _clock.Delay(poll, ct).ConfigureAwait(false);
|
||||
DateTimeOffset lastSign;
|
||||
DateTimeOffset? leftAt;
|
||||
lock (_gate)
|
||||
{
|
||||
if (!ReferenceEquals(_lease, lease))
|
||||
@@ -735,15 +801,22 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
}
|
||||
|
||||
lastSign = _lastDrivingSign;
|
||||
leftAt = _leftAt;
|
||||
}
|
||||
|
||||
if (_clock.Now - lastSign < grace)
|
||||
// Docker: the page of the browser left, or its last view closed by the page, and for a moment nothing came
|
||||
// back (answer of 25 November 2026). Otherwise the long wait of a lease nobody uses.
|
||||
var now = _clock.Now;
|
||||
var left = leftAt is { } at && now - (at > lastSign ? at : lastSign) >= leaveGrace;
|
||||
if (!left && now - lastSign < grace)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Before the page goes back to the engine: the copy of the session (S4b, answer 5).
|
||||
if (!await CopyBeforeLeaseEndsAsync(lease, lastSign, poll, ct).ConfigureAwait(false))
|
||||
// Before the page goes back to the engine: the copy of the session (S4b, answer 5; leaving the page in
|
||||
// Docker, answer of 25 November 2026).
|
||||
var what = left ? PageLeftText : "Fine della guida del browser";
|
||||
if (!await CopyBeforeLeaseEndsAsync(lease, lastSign, poll, what, ct).ConfigureAwait(false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -753,7 +826,9 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
// the lease, so that nothing slips in between.
|
||||
if (ReleaseIdleLease(lease, lastSign))
|
||||
{
|
||||
_log.Info("collegamento", $"Nessuna vista del browser aperta da {ItalianText.Duration(grace)} senza «Ho finito» né «Annulla»: il motore può riprendere.");
|
||||
_log.Info("collegamento", left
|
||||
? $"{PageLeftText}: nessuna vista del browser riaperta, il motore può riprendere."
|
||||
: $"Nessuna vista del browser aperta da {ItalianText.Duration(grace)} senza «Ho finito» né «Annulla»: il motore può riprendere.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -777,7 +852,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
/// (<paramref name="poll"/>) of the copy is that hold, not Alberto. False when the lease must not end now: a sign of
|
||||
/// driving came while the copy waited for its turn.
|
||||
/// </summary>
|
||||
private async Task<bool> CopyBeforeLeaseEndsAsync(IDisposable lease, DateTimeOffset lastSign, TimeSpan poll, CancellationToken ct)
|
||||
private async Task<bool> CopyBeforeLeaseEndsAsync(IDisposable lease, DateTimeOffset lastSign, TimeSpan poll, string what, CancellationToken ct)
|
||||
{
|
||||
if (_copier is null)
|
||||
{
|
||||
@@ -828,7 +903,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
return false;
|
||||
}
|
||||
|
||||
await CopyOnLetGoAsync("Fine della guida del browser", StillAlbertos, ct).ConfigureAwait(false);
|
||||
await CopyOnLetGoAsync(what, StillAlbertos, ct).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
@@ -1345,6 +1420,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
var taken = (_lease, _leaseWatch);
|
||||
_lease = null;
|
||||
_leaseWatch = null;
|
||||
_leftAt = null;
|
||||
return taken;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user