Files
Febe/src/Febe.Web/Connection/IConnectionService.cs
T
Alby96andClaude Opus 5.5 2fc4b40c41
verifica / controlli (push) Successful in 24s
verifica / prove (push) Failing after 41m21s
verifica / installatore (push) Skipped
verifica / immagine (push) Skipped
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>
2026-11-25 10:52:51 +01:00

129 lines
6.5 KiB
C#

namespace Febe.Web.Connection;
/// <summary>State of the link to Instagram shown at the bottom of the sidebar and on the Collegamento page (spec §4.1).</summary>
public enum ConnectionState
{
/// <summary>No session in the browser profile: «Non collegato».</summary>
NotConnected,
/// <summary>Session cookie present: «Collegato».</summary>
Connected,
/// <summary>The engine stopped for a challenge or a disconnection: «Verifica richiesta».</summary>
VerificationRequired,
/// <summary>The browser is not available (starting, crashed, demo without browser).</summary>
BrowserUnavailable,
/// <summary>
/// The session cookie is in the browser, but the raccolta «richieste» has no readable saved session to send it with
/// (issue #36, S4b): «Serve «Ho finito»». The engine waits until a copy is made.
/// </summary>
SessionCopyMissing,
}
/// <summary>
/// The saved session of the raccolta «richieste» as the Collegamento page shows it (issue #36, S4b): counts and names
/// only, never a value (rule 10).
/// </summary>
/// <param name="State"><see cref="Present"/>, <see cref="None"/> or <see cref="Unreadable"/>.</param>
/// <param name="CopiedAt">When the copy was made; null when there is none or it is not known.</param>
/// <param name="Cookies">How many cookies it holds.</param>
/// <param name="ValuesPresent">Values of the page it holds.</param>
/// <param name="ValuesExpected">Values of the page the copy reads.</param>
/// <param name="MissingValues">Names of the values it lacks.</param>
/// <param name="DocIdsPresent">doc_id it holds.</param>
/// <param name="DocIdsExpected">doc_id the copy reads.</param>
/// <param name="MissingDocIds">Operations whose doc_id it lacks.</param>
/// <param name="NeededMissing">How many of those a configured operation sends (its requests do not leave).</param>
public sealed record SavedSessionStatus(
string State,
DateTimeOffset? CopiedAt,
int Cookies,
int ValuesPresent,
int ValuesExpected,
IReadOnlyList<string> MissingValues,
int DocIdsPresent,
int DocIdsExpected,
IReadOnlyList<string> MissingDocIds,
int NeededMissing)
{
/// <summary>A readable saved session.</summary>
public const string Present = "present";
/// <summary>No saved session.</summary>
public const string None = "none";
/// <summary>A file that cannot be read: counts as none.</summary>
public const string Unreadable = "unreadable";
}
/// <summary>What the interface knows about the link to Instagram.</summary>
/// <param name="State">Current state.</param>
/// <param name="Username">Connected account (from the data the page received, hypothesis H10), when known.</param>
/// <param name="DisplayName">Display name, when known.</param>
/// <param name="UserIsDriving">True while Alberto is using the browser (login page, remote view, browser window): the engine is still.</param>
/// <param name="CurrentUrl">Address shown in the remote view's address bar, without query string.</param>
/// <param name="SavedSession">The saved session (raccolta «richieste»); null when this start keeps none.</param>
public sealed record ConnectionStatus(
ConnectionState State,
string? Username,
string? DisplayName,
bool UserIsDriving,
string? CurrentUrl,
SavedSessionStatus? SavedSession = null);
/// <summary>Result of «Ho finito» on the Collegamento page.</summary>
/// <param name="Connected">True when the session cookie now exists.</param>
/// <param name="Message">Italian message for the page (what happened, what Febe did, what Alberto should do).</param>
public sealed record FinishResult(bool Connected, string Message);
/// <summary>
/// The link to Instagram (spec §4.1, §10.3 «Collegamento» and «Browser» pages). Implemented by the server/desktop
/// composition over the real browser host, and by the demo mode with a fake driven by the scene.
/// Opening the login page here is not an engine action (rule 7): Alberto is using the browser and the engine is still.
/// </summary>
public interface IConnectionService
{
Task<ConnectionStatus> GetStatusAsync(CancellationToken ct);
/// <summary>
/// Alberto starts using the browser: the engine stops acting (UserIsDriving), and when <paramref name="openLogin"/>
/// is true the browser loads the real Instagram login page. Windows: the browser window is brought to the front.
/// </summary>
Task BeginUserDrivingAsync(bool openLogin, CancellationToken ct);
/// <summary>«Ho finito»: checks that the session cookie exists (value never read), hides the browser, ends user driving.</summary>
Task<FinishResult> FinishAsync(CancellationToken ct);
/// <summary>«Annulla»: ends user driving and puts the browser on the empty rest page.</summary>
Task CancelAsync(CancellationToken ct);
/// <summary>
/// «Apri il browser» on Windows (spec §10.3, issue #52): the window comes to the front and holds the engine still
/// while it is on screen. A browser resting on the empty page first opens the start page (the site's home when
/// connected, the login page otherwise); with <paramref name="openLogin"/> the login page in any case (the red strip
/// of a disconnection).
/// </summary>
Task ShowBrowserAsync(bool openLogin, CancellationToken ct);
/// <summary>
/// The Febe page that took the browser was left (another page, a reload, the tab closed) while the browser is a
/// window of its own (Windows, issue #52): only the page's hold ends. The window stays as it is, on screen and with
/// its page, until Alberto closes it or presses «Ho finito».
/// </summary>
Task ReleaseAsync(CancellationToken ct);
/// <summary>
/// The Febe page that took the browser was left (another page, a reload, the tab closed) while the browser is the
/// remote view (Docker, answer of Alberto of 25 November 2026, spec §6.0 «Quando si copia»): like closing the window
/// «Browser di Febe» on Windows, not like «Annulla». If within a moment no view opens again and no «Accedi» / «Usa il
/// browser» comes (a reload is not leaving), the session is copied while the page is still his, and then the page goes
/// back to the engine. By default, for a service without a saved session to copy, it is «Annulla».
/// </summary>
Task LeavePageAsync(CancellationToken ct) => CancelAsync(ct);
/// <summary>«Scollega» (after confirmation in the UI): stops the engine and deletes the browser profile.</summary>
Task DisconnectAsync(CancellationToken ct);
}