Unione di funzione/sessione-s4b in funzione/codec-immagini (catena della 0.3.0)
Porta nel ramo dei codec le regole e le risposte del 25 novembre (ramo dei documenti) e la tappa S4b della sessione salvata, così che il ramo si unisca in main dopo i due precedenti senza conflitti da risolvere di nuovo. Conflitti risolti tenendo le due intenzioni: - Directory.Packages.props: il commento «Niente componenti esterni» dei documenti, senza le righe di SkiaSharp, che questo ramo ha già tolto (C1). - docs/decisioni.md: tutte le righe aggiunte dai due lati, prima le 39 della catena (documenti e S4b), poi le 23 dei codec. - docs/docker.md: ffmpeg «fino alla tappa C3» dei documenti più la riga dei codec «Nessuna libreria per le immagini». - docs/guida/Sviluppo.md: la regola «Niente componenti esterni» dei documenti, con SkiaSharp detto già uscito con la tappa C1 e i codec e il disegnatore di casa che lo sostituiscono. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
a0e7404297
62 files changed
+2944
-242
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Collection.Requests;
|
||||
using Febe.Core.Storage;
|
||||
using Febe.Web.Connection;
|
||||
using Febe.Web.Engine;
|
||||
using Febe.Web.Native;
|
||||
@@ -36,7 +38,9 @@ public static class ConnectionApi
|
||||
});
|
||||
|
||||
// «Annulla», or a page left without either button ({ pageLeft: true }). On Windows the browser is a window of its
|
||||
// own: leaving a page of Febe leaves it as it is, on screen until Alberto closes it (issue #52).
|
||||
// own: leaving a page of Febe leaves it as it is, on screen until Alberto closes it (issue #52). In Docker leaving
|
||||
// the page lets go of the browser like closing that window: the session is copied, not cancelled (answer of
|
||||
// 25 November 2026). Only the button «Annulla» cancels without copying.
|
||||
endpoints.MapPost("/api/connection/cancel", async (HttpContext context, IConnectionService connection, IBrowserWindow window, CancellationToken ct) =>
|
||||
{
|
||||
var body = await ApiHttp.OptionalBodyAsync(context, FebeJsonContext.Default.CancelDrivingRequest, new CancelDrivingRequest(false)).ConfigureAwait(false);
|
||||
@@ -44,6 +48,10 @@ public static class ConnectionApi
|
||||
{
|
||||
await connection.ReleaseAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
else if (body.PageLeft)
|
||||
{
|
||||
await connection.LeavePageAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await connection.CancelAsync(ct).ConfigureAwait(false);
|
||||
@@ -57,19 +65,54 @@ public static class ConnectionApi
|
||||
await connection.DisconnectAsync(ct).ConfigureAwait(false);
|
||||
return Results.NoContent();
|
||||
});
|
||||
|
||||
// What an incomplete copy of the session does (issue #36, S4b, answer 9): read at every copy, no restart.
|
||||
endpoints.MapGet("/api/connection/settings", async (IFebeStorage storage, CancellationToken ct) =>
|
||||
ApiHttp.Json(await SettingsAsync(storage, ct).ConfigureAwait(false), FebeJsonContext.Default.ConnectionSettingsDto));
|
||||
|
||||
endpoints.MapPut("/api/connection/settings", async (HttpContext context, IFebeStorage storage, CancellationToken ct) =>
|
||||
{
|
||||
var body = await ApiHttp.BodyAsync(context, FebeJsonContext.Default.ConnectionSettingsDto).ConfigureAwait(false);
|
||||
var choice = SessionCopySettings.Parse(body.IncompleteCopy)
|
||||
?? throw new BadRequestException($"Scelta sconosciuta per la copia incompleta: ammesse «{SessionCopySettings.ReplaceText}» e «{SessionCopySettings.KeepCompleteText}».");
|
||||
await new SessionCopySettings(choice).SaveAsync(storage.Settings, ct).ConfigureAwait(false);
|
||||
return ApiHttp.Json(await SettingsAsync(storage, ct).ConfigureAwait(false), FebeJsonContext.Default.ConnectionSettingsDto);
|
||||
});
|
||||
}
|
||||
|
||||
private static async Task<ConnectionSettingsDto> SettingsAsync(IFebeStorage storage, CancellationToken ct)
|
||||
{
|
||||
var settings = await SessionCopySettings.LoadAsync(storage.Settings, ct).ConfigureAwait(false);
|
||||
return new ConnectionSettingsDto(SessionCopySettings.ToText(settings.IncompleteCopy));
|
||||
}
|
||||
|
||||
public static ConnectionStatusDto ToDto(ConnectionStatus status)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(status);
|
||||
return new ConnectionStatusDto(State(status.State), status.Username, status.DisplayName, status.UserIsDriving, status.CurrentUrl);
|
||||
return new ConnectionStatusDto(State(status.State), status.Username, status.DisplayName, status.UserIsDriving, status.CurrentUrl, ToDto(status.SavedSession));
|
||||
}
|
||||
|
||||
/// <summary>The saved session in counts and names; null without one.</summary>
|
||||
public static SavedSessionDto? ToDto(SavedSessionStatus? saved) => saved is null
|
||||
? null
|
||||
: new SavedSessionDto(
|
||||
saved.State,
|
||||
saved.CopiedAt?.ToUnixTimeMilliseconds(),
|
||||
saved.Cookies,
|
||||
saved.ValuesPresent,
|
||||
saved.ValuesExpected,
|
||||
saved.MissingValues,
|
||||
saved.DocIdsPresent,
|
||||
saved.DocIdsExpected,
|
||||
saved.MissingDocIds,
|
||||
saved.NeededMissing);
|
||||
|
||||
public static string State(ConnectionState state) => state switch
|
||||
{
|
||||
ConnectionState.NotConnected => "notConnected",
|
||||
ConnectionState.Connected => "connected",
|
||||
ConnectionState.VerificationRequired => "verificationRequired",
|
||||
ConnectionState.SessionCopyMissing => "copyMissing",
|
||||
_ => "browserUnavailable",
|
||||
};
|
||||
}
|
||||
@@ -84,8 +84,9 @@ public static class EngineApi
|
||||
/// <summary>
|
||||
/// The engine as the interface needs it. The link comes from the session cookie, never from whether «Tu» is known:
|
||||
/// the name of the connected account may come much later (H10), and meanwhile the sidebar says «Collegato» with
|
||||
/// «Nome non ancora noto». The engine looks at the cookie on every turn and its mode says so; when it does not run
|
||||
/// (or there is none in this process) the connection is asked.
|
||||
/// «Nome non ancora noto». The engine looks at the cookie on every turn and its mode says so, and whether the copy for
|
||||
/// the requests is missing too (<see cref="EngineSnapshot.SessionCopyMissing"/>, no round trip to the browser at every
|
||||
/// event); only when it does not run (or there is none in this process) the connection is asked.
|
||||
/// </summary>
|
||||
public static async Task<EngineDto> SnapshotAsync(IEngineMonitor monitor, IFebeStorage storage, BrowserUseTracker tracker, IClock clock, IConnectionService connection, CancellationToken ct)
|
||||
{
|
||||
@@ -98,10 +99,16 @@ public static class EngineApi
|
||||
var mine = await storage.Accounts.GetMineAsync(ct).ConfigureAwait(false);
|
||||
var state = snapshot.Mode switch
|
||||
{
|
||||
EngineMode.NotConnected => "notConnected",
|
||||
// The cookie is there but the copy for the requests is missing (S4b): «Serve «Ho finito»», with the account.
|
||||
EngineMode.NotConnected => snapshot.SessionCopyMissing ? "copyMissing" : "notConnected",
|
||||
EngineMode.StoppedForVerification => "verification",
|
||||
EngineMode.Disconnected => "disconnected",
|
||||
EngineMode.Off => (await connection.GetStatusAsync(ct).ConfigureAwait(false)).State == ConnectionState.Connected ? "connected" : "notConnected",
|
||||
EngineMode.Off => (await connection.GetStatusAsync(ct).ConfigureAwait(false)).State switch
|
||||
{
|
||||
ConnectionState.Connected => "connected",
|
||||
ConnectionState.SessionCopyMissing => "copyMissing",
|
||||
_ => "notConnected",
|
||||
},
|
||||
_ => "connected",
|
||||
};
|
||||
var link = state == "notConnected"
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Febe.Web.Api;
|
||||
[JsonSerializable(typeof(LoginDto))]
|
||||
[JsonSerializable(typeof(Library.LibraryChange))]
|
||||
[JsonSerializable(typeof(ConnectionStatusDto))]
|
||||
[JsonSerializable(typeof(ConnectionSettingsDto))]
|
||||
[JsonSerializable(typeof(BeginDrivingRequest))]
|
||||
[JsonSerializable(typeof(CancelDrivingRequest))]
|
||||
[JsonSerializable(typeof(FinishDto))]
|
||||
|
||||
@@ -5,8 +5,33 @@ namespace Febe.Web.Api;
|
||||
|
||||
// ---------------------------------------------------------------- connection (PROTOCOLLO.md)
|
||||
|
||||
/// <summary><c>GET /api/connection</c>. <see cref="State"/>: notConnected, connected, verificationRequired, browserUnavailable.</summary>
|
||||
public sealed record ConnectionStatusDto(string State, string? Username, string? DisplayName, bool UserIsDriving, string? CurrentUrl);
|
||||
/// <summary>
|
||||
/// <c>GET /api/connection</c>. <see cref="State"/>: notConnected, connected, copyMissing, verificationRequired,
|
||||
/// browserUnavailable. <see cref="SavedSession"/> only with the raccolta «richieste».
|
||||
/// </summary>
|
||||
public sealed record ConnectionStatusDto(string State, string? Username, string? DisplayName, bool UserIsDriving, string? CurrentUrl, SavedSessionDto? SavedSession = null);
|
||||
|
||||
/// <summary>
|
||||
/// The saved session in counts and names (issue #36, S4b): <see cref="State"/> present, none or unreadable;
|
||||
/// <see cref="CopiedAt"/> Unix milliseconds. Never a value.
|
||||
/// </summary>
|
||||
public sealed record SavedSessionDto(
|
||||
string State,
|
||||
long? CopiedAt,
|
||||
int Cookies,
|
||||
int ValuesPresent,
|
||||
int ValuesExpected,
|
||||
IReadOnlyList<string> MissingValues,
|
||||
int DocIdsPresent,
|
||||
int DocIdsExpected,
|
||||
IReadOnlyList<string> MissingDocIds,
|
||||
int NeededMissing);
|
||||
|
||||
/// <summary>
|
||||
/// <c>GET/PUT /api/connection/settings</c>: what an incomplete copy of the session does, <c>sostituisci</c> (the
|
||||
/// default) or <c>tieni-completa</c>.
|
||||
/// </summary>
|
||||
public sealed record ConnectionSettingsDto(string IncompleteCopy);
|
||||
|
||||
/// <summary><c>POST /api/connection/begin</c>.</summary>
|
||||
public sealed record BeginDrivingRequest(bool OpenLogin);
|
||||
|
||||
@@ -14,6 +14,48 @@ public enum ConnectionState
|
||||
|
||||
/// <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>
|
||||
@@ -22,12 +64,14 @@ public enum ConnectionState
|
||||
/// <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);
|
||||
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>
|
||||
@@ -70,6 +114,15 @@ public interface IConnectionService
|
||||
/// </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);
|
||||
}
|
||||
@@ -7,11 +7,12 @@ Lo usano due parti scritte in parallelo: non cambiarlo senza aggiornare entrambe
|
||||
|
||||
| Endpoint | Corpo e risposta |
|
||||
|---|---|
|
||||
| `GET /api/connection` | `{ state: "notConnected"\|"connected"\|"verificationRequired"\|"browserUnavailable", username, displayName, userIsDriving, currentUrl }` |
|
||||
| `GET /api/connection` | `{ state: "notConnected"\|"connected"\|"copyMissing"\|"verificationRequired"\|"browserUnavailable", username, displayName, userIsDriving, currentUrl, savedSession }` |
|
||||
| `POST /api/connection/begin` | `{ openLogin: bool }` → 204. Alberto usa il browser; con `openLogin` il browser carica la pagina di accesso vera; senza, se il browser è a riposo (`about:blank`) apre la pagina iniziale (sotto) |
|
||||
| `POST /api/connection/finish` | → `{ connected: bool, message }` («Ho finito») |
|
||||
| `POST /api/connection/cancel` | corpo facoltativo `{ pageLeft: bool }` → 204 («Annulla»; con `pageLeft` la pagina è stata lasciata, sotto) |
|
||||
| `POST /api/connection/disconnect` | → 204 («Scollega», dopo la conferma nell'interfaccia) |
|
||||
| `GET /api/connection/settings`, `PUT /api/connection/settings` | `{ incompleteCopy: "sostituisci"\|"tieni-completa" }`: che cosa fa una copia della sessione incompleta (raccolta «richieste»); un altro valore → 400 |
|
||||
| `POST /api/browser/show` | corpo facoltativo `{ openLogin: bool }` → `{ message }`. Solo Windows: porta in primo piano la finestra «Browser di Febe»; come `begin` apre la pagina di accesso (`openLogin`) o, se era a riposo, la pagina iniziale |
|
||||
|
||||
**Pagina iniziale** (issue #52): la home del sito se Febe è collegato e non scollegato da Instagram, altrimenti la
|
||||
@@ -27,9 +28,23 @@ di una disconnessione apre il browser con `openLogin: true` (in Docker la pagina
|
||||
|
||||
In modalità dimostrativa la scena `scollegato` dà `notConnected`, la scena `fermo` dà `verificationRequired`.
|
||||
|
||||
**Raccolta «richieste»** (issue #36, S4b): `savedSession` è `null` senza sessione salvata in questo avvio («pagine», o
|
||||
nessuna operazione configurata); altrimenti `{ state: "present"|"none"|"unreadable", copiedAt (ms Unix o null), cookies,
|
||||
valuesPresent, valuesExpected, missingValues: [nomi], docIdsPresent, docIdsExpected, missingDocIds: [operazioni],
|
||||
neededMissing }`: solo conteggi e nomi, mai valori. Con il cookie di sessione nel browser ma senza una sessione salvata
|
||||
leggibile lo stato è `copyMissing` («Serve «Ho finito»»): il motore aspetta, e `/api/engine` dice `copyMissing` nel
|
||||
collegamento. La sessione si copia a «Ho finito», alla chiusura della finestra del browser su Windows, lasciando la
|
||||
pagina del browser in Docker (sotto) e quando il permesso di guida finisce da solo, sempre prima che la pagina torni al
|
||||
motore. «Annulla» non copia mai.
|
||||
|
||||
L'interfaccia manda `cancel` con `{ "pageLeft": true }` anche quando Alberto lascia la pagina Browser, o la pagina
|
||||
Collegamento mentre accede, senza «Ho finito» né «Annulla»: un'altra pagina, la scheda chiusa o ricaricata (`fetch`
|
||||
con `keepalive`, che porta l'`Origin` dell'interfaccia). In Docker vale come «Annulla» (il browser torna a riposo).
|
||||
con `keepalive`, che porta l'`Origin` dell'interfaccia). In Docker non è «Annulla» (`IConnectionService.LeavePageAsync`,
|
||||
risposta di Alberto del 25 novembre 2026): è come chiudere la finestra del browser su Windows. Febe lo nota e aspetta
|
||||
5 secondi; anche la vista remota chiusa dalla sua pagina (scheda chiusa, collegamento perso, non sostituita da un'altra
|
||||
scheda) fa ricominciare l'attesa. Se in quel tempo non si apre un'altra vista e non arriva un `begin` (una pagina
|
||||
ricaricata fa tutti e due), copia la sessione come alla chiusura della finestra (solo da una pagina del sito che non sia
|
||||
di accesso o di verifica), poi il permesso finisce e il motore rimette il browser a riposo.
|
||||
Su Windows, dove il browser è una finestra a parte, finisce solo il permesso tenuto dalla pagina: la finestra resta
|
||||
com'è, sullo schermo e con la sua pagina, finché Alberto non la chiude (e finché è sullo schermo il motore resta
|
||||
fermo). Dopo un «Ho finito» riuscito la pagina chiude la vista remota e non manda un nuovo `begin`.
|
||||
|
||||
@@ -802,6 +802,15 @@ input[type=range].cursore.lungo::-webkit-slider-thumb{border-color:var(--accento
|
||||
.collega-destra h2.sez{margin-bottom:12px}
|
||||
.collega-destra .avviso{font-size:13.5px;line-height:1.5;padding:13px 16px}
|
||||
.nota-password{background:var(--accento-tinta)}
|
||||
.sessione-salvata{padding:14px 16px;font-size:13.5px;line-height:1.5}
|
||||
.sessione-salvata p{margin:0 0 6px}
|
||||
.sessione-salvata h2.sez{margin-bottom:8px}
|
||||
.sessione-salvata h3.sez{font-size:13.5px;font-weight:650;margin:12px 0 8px}
|
||||
.sessione-salvata .avviso{margin:4px 0 8px}
|
||||
.sessione-salvata .scelte{display:flex;flex-direction:column;gap:10px}
|
||||
.sessione-salvata .scelte .voce{align-items:flex-start}
|
||||
.sessione-salvata .scelte .voce .tondo{margin-top:2px}
|
||||
.sessione-salvata .scelte small{display:block;color:var(--testo-2);font-size:12.5px}
|
||||
.passi-collegamento{list-style:none;margin:0 0 8px;padding:0;display:flex;flex-direction:column;gap:18px}
|
||||
.passi-collegamento li{display:flex;gap:14px}
|
||||
.passi-collegamento .numero{width:24px;height:24px;border-radius:50%;flex:none;display:inline-flex;align-items:center;justify-content:center;background:var(--accento-tinta);color:var(--accento-scuro);font-weight:650;font-size:12.5px;margin-top:1px}
|
||||
|
||||
@@ -63,7 +63,7 @@ function renderStatus(state) {
|
||||
const s = state.snapshot;
|
||||
const meter = s.profilesOpenedToday;
|
||||
const connection = state.connection;
|
||||
const linkState = t(connection.state === 'verification' ? 'stato.verifica' : connection.state === 'disconnected' ? 'stato.scollegato' : 'stato.collegato');
|
||||
const linkState = t(connection.state === 'verification' ? 'stato.verifica' : connection.state === 'disconnected' ? 'stato.scollegato' : connection.state === 'copyMissing' ? 'stato.copiaMancante' : 'stato.collegato');
|
||||
// The own account is known only after the first sweep (a verification can come before it): no «@null».
|
||||
const who = connection.state === 'notConnected'
|
||||
? h('div.chi', h('span.av.segnaposto', icon('user', 's')),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Browser (spec §10.3 «Apri il browser»; mockup 10 without the steps column): in Docker the remote view of the
|
||||
// server's browser and «Ho finito»; on Windows the browser is its own window. While Alberto uses the browser the
|
||||
// engine is still; «Ho finito» lets «Riprendi» become active after a verification. Leaving the page without «Ho finito»
|
||||
// (another page, a reload, closing the tab) gives the browser back, like «Annulla» (on Windows the window stays as it
|
||||
// is until Alberto closes it). A browser at rest opens its start page; «?accesso=1» (the red strip of a disconnection)
|
||||
// (another page, a reload, closing the tab) gives the browser back, like closing the window on Windows: the server copies
|
||||
// the session if no view opens again within a moment (on Windows the window stays as it is until Alberto closes it). A browser at rest opens its start page; «?accesso=1» (the red strip of a disconnection)
|
||||
// opens the login page, once: the parameter leaves the address straight away.
|
||||
|
||||
import { api } from '../core/api.js';
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// the steps «Come collegarti», the note that the password goes only to Instagram (keys pass through the server without
|
||||
// being recorded), the risk note, Annulla and «Ho finito». Windows: the browser is the separate window «Browser di
|
||||
// Febe» and the large area says so, with «Portalo in primo piano». When connected: the account, «Usa il browser» and
|
||||
// «Scollega» with its confirmation. While Alberto uses the browser the engine is still.
|
||||
// «Scollega» with its confirmation. While Alberto uses the browser the engine is still. With the raccolta «richieste»
|
||||
// (issue #36, S4b) the page also shows the saved session in counts and names (never values), the choice for an
|
||||
// incomplete copy, and «Serve «Ho finito»» when the browser is connected but the copy is missing.
|
||||
|
||||
import { api } from '../core/api.js';
|
||||
import { caps } from '../core/context.js';
|
||||
@@ -10,10 +12,10 @@ import { h, icon, fill } from '../core/dom.js';
|
||||
import { engineState, refreshEngine } from '../core/engine.js';
|
||||
import { navigate } from '../core/shell.js';
|
||||
import { t } from '../core/text.js';
|
||||
import { avatar, confirmDialog, label, showError, toast } from '../core/ui.js';
|
||||
import { avatar, confirmDialog, label, radio, showError, toast } from '../core/ui.js';
|
||||
import { remoteView } from './remote-view.js';
|
||||
|
||||
const STATE_KIND = { notConnected: 'ambra', connected: 'verde', verificationRequired: 'rosso', browserUnavailable: '' };
|
||||
const STATE_KIND = { notConnected: 'ambra', connected: 'verde', copyMissing: 'ambra', verificationRequired: 'rosso', browserUnavailable: '' };
|
||||
|
||||
/** True while the engine waits for «Riprendi» (the stop strip of a verification or a disconnection). */
|
||||
function waitsForResume(state) {
|
||||
@@ -40,9 +42,10 @@ export async function beginDriving(openLogin) {
|
||||
/**
|
||||
* The browser as a page uses it (spec §4.1, §10.3: the engine is still only while Alberto uses the browser). begin()
|
||||
* takes it; «Ho finito», «Annulla» and «Scollega» give it back on the server, and the page calls settled(). Leaving the
|
||||
* page in any other way — another page, a reload, closing the tab — gives it back too: in Docker like «Annulla» (the
|
||||
* browser goes back to the empty page and the engine may work again); on Windows the window «Browser di Febe» stays as
|
||||
* it is, on screen until Alberto closes it (issue #52), and only the page's hold ends.
|
||||
* page in any other way — another page, a reload, closing the tab — gives it back too: in Docker like closing the
|
||||
* window on Windows, not like «Annulla» (answer of 25 November 2026: if no view opens again within a moment, the
|
||||
* server copies the session and the engine may work again; a reload opens the view again); on Windows the window
|
||||
* «Browser di Febe» stays as it is, on screen until Alberto closes it (issue #52), and only the page's hold ends.
|
||||
*/
|
||||
export function drivingLease(page) {
|
||||
let held = false;
|
||||
@@ -120,6 +123,7 @@ export async function mountConnection(page) {
|
||||
fill(stateLabel, label(t(`impostazioni.collegamento.stati.${status.state}`), STATE_KIND[status.state] || ''));
|
||||
if (status.state === 'connected') drawConnected();
|
||||
else if (status.state === 'browserUnavailable') drawUnavailable();
|
||||
else if (status.state === 'copyMissing') drawLogin({ copyMissing: true });
|
||||
else drawLogin();
|
||||
}
|
||||
|
||||
@@ -145,15 +149,17 @@ export async function mountConnection(page) {
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------------------------------- login or verification
|
||||
function drawLogin() {
|
||||
function drawLogin({ copyMissing = false } = {}) {
|
||||
const verification = status.state === 'verificationRequired';
|
||||
// Connected but without the copy for the requests: the start page (the site's home), never the login page.
|
||||
const login = !verification && !copyMissing;
|
||||
waitingResume = false;
|
||||
closeView();
|
||||
lease.begin(!verification);
|
||||
lease.begin(login);
|
||||
if (windows) {
|
||||
fill(left, windowPanel());
|
||||
} else {
|
||||
view = remoteView(page, { url: status.currentUrl, login: !verification });
|
||||
view = remoteView(page, { url: status.currentUrl, login });
|
||||
fill(left, view.element);
|
||||
}
|
||||
const steps = t(windows ? 'impostazioni.collegamento.passiWindows' : 'impostazioni.collegamento.passi');
|
||||
@@ -161,6 +167,8 @@ export async function mountConnection(page) {
|
||||
fill(right,
|
||||
verification
|
||||
? h('div.avviso.rosso', icon('octagon-alert', 's'), h('span', h('b', t('impostazioni.collegamento.verificaTitolo')), ' ', t('impostazioni.collegamento.verificaTesto')))
|
||||
: copyMissing
|
||||
? h('div.avviso.ambra', icon('triangle-alert', 's'), h('span', h('b', t('impostazioni.collegamento.copiaMancanteTitolo')), ' ', t('impostazioni.collegamento.copiaMancanteTesto')))
|
||||
: h('div',
|
||||
h('h2.sez', t('impostazioni.collegamento.come')),
|
||||
h('ol.passi-collegamento', (Array.isArray(steps) ? steps : []).map((s, i) => h('li', h('span.numero', String(i + 1)), h('div', h('b', s.titolo), h('p', s.testo)))))),
|
||||
@@ -168,6 +176,7 @@ export async function mountConnection(page) {
|
||||
h('div.avviso.ambra', icon('triangle-alert', 's'), h('span', t('impostazioni.collegamento.rischio'))),
|
||||
// Windows: one engine per account (spec §5) said before the login too; Docker keeps mockup 10 as it is.
|
||||
windows ? h('div.avviso', icon('info', 's'), h('span', t('impostazioni.collegamento.unMotore'))) : null,
|
||||
copyMissing ? savedSessionBox(status.savedSession, page) : null,
|
||||
message,
|
||||
h('div.molla'),
|
||||
h('div.bottoni-collegamento',
|
||||
@@ -235,7 +244,8 @@ export async function mountConnection(page) {
|
||||
fill(right,
|
||||
passwordNote(windows),
|
||||
h('div.avviso.ambra', icon('triangle-alert', 's'), h('span', t('impostazioni.collegamento.rischio'))),
|
||||
h('div.avviso', icon('info', 's'), h('span', t('impostazioni.collegamento.unMotore'))));
|
||||
h('div.avviso', icon('info', 's'), h('span', t('impostazioni.collegamento.unMotore'))),
|
||||
savedSessionBox(status.savedSession, page));
|
||||
}
|
||||
|
||||
async function useBrowser() {
|
||||
@@ -287,6 +297,81 @@ export async function mountConnection(page) {
|
||||
await draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* The saved session of the raccolta «richieste» (issue #36, S4b): when it was copied, the values and doc_id present
|
||||
* and the names of the missing ones — counts and names only, the server never sends a value — and the choice for an
|
||||
* incomplete copy. Nothing without a saved session in this start («pagine»).
|
||||
*/
|
||||
export function savedSessionBox(saved, page) {
|
||||
if (!saved) return null;
|
||||
const k = (key, vars) => t(`impostazioni.collegamento.salvata.${key}`, vars);
|
||||
const lines = [];
|
||||
if (saved.state === 'present') {
|
||||
if (saved.copiedAt) {
|
||||
const when = new Date(saved.copiedAt).toLocaleString('it-IT', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
lines.push(h('p', k('copiata', { quando: when })));
|
||||
}
|
||||
lines.push(h('p.muto', [
|
||||
k('valori', { presenti: String(saved.valuesPresent), attesi: String(saved.valuesExpected) }),
|
||||
k('docId', { presenti: String(saved.docIdsPresent), attesi: String(saved.docIdsExpected) }),
|
||||
k('cookie', { n: String(saved.cookies) }),
|
||||
].join(' ')));
|
||||
const missing = [...(saved.missingValues || []), ...(saved.missingDocIds || [])];
|
||||
if (missing.length) lines.push(h('p', k('mancano', { nomi: missing.join(', ') })));
|
||||
lines.push(saved.neededMissing
|
||||
? h('div.avviso.ambra', icon('triangle-alert', 's'), h('span', k('servono', { n: String(saved.neededMissing) })))
|
||||
: h('p', k('completa')));
|
||||
} else {
|
||||
lines.push(h('p', k(saved.state === 'unreadable' ? 'illeggibile' : 'nessuna')));
|
||||
}
|
||||
|
||||
// Neither choice is shown as chosen, and neither can be picked, until the server says which one is stored: the page
|
||||
// never claims a choice the next copy will not follow. Once Alberto picks one, a late answer no longer changes it;
|
||||
// a choice the server did not save goes back to the one before.
|
||||
let saved = null;
|
||||
let chosen = false;
|
||||
const show = (value) => {
|
||||
keep.input.checked = value === 'tieni-completa';
|
||||
replace.input.checked = value === 'sostituisci';
|
||||
};
|
||||
const choose = async (value) => {
|
||||
chosen = true;
|
||||
const before = saved;
|
||||
try {
|
||||
const settings = await api('/api/connection/settings', { method: 'PUT', body: { incompleteCopy: value } });
|
||||
saved = settings && settings.incompleteCopy ? settings.incompleteCopy : value;
|
||||
unknown.hidden = true;
|
||||
toast(k('salvato'));
|
||||
} catch (error) {
|
||||
show(before);
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
const replace = radio({ name: 'copia-incompleta', value: 'sostituisci', onchange: choose, labelNode: h('span', h('b', k('sostituisci')), h('small', k('sostituisciAiuto'))) });
|
||||
const keep = radio({ name: 'copia-incompleta', value: 'tieni-completa', onchange: choose, labelNode: h('span', h('b', k('tieni')), h('small', k('tieniAiuto'))) });
|
||||
const unknown = h('p.aiuto.piccolo.scelta-ignota', { hidden: true }, k('sceltaIgnota'));
|
||||
for (const choice of [replace, keep]) choice.input.disabled = true;
|
||||
api('/api/connection/settings', { signal: page && page.signal }).then((settings) => {
|
||||
if (chosen) return;
|
||||
saved = settings.incompleteCopy;
|
||||
show(saved);
|
||||
}).catch(() => {
|
||||
if (page && page.signal && page.signal.aborted) return; // the page was left
|
||||
if (!chosen) unknown.hidden = false;
|
||||
}).finally(() => {
|
||||
if (page && page.signal && page.signal.aborted) return;
|
||||
for (const choice of [replace, keep]) choice.input.disabled = false;
|
||||
});
|
||||
|
||||
return h('div.pannello.sessione-salvata',
|
||||
h('h2.sez', k('titolo')),
|
||||
...lines,
|
||||
h('p.aiuto.piccolo', k('nota')),
|
||||
h('h3.sez', k('incompleta')),
|
||||
h('div.scelte', { role: 'radiogroup', 'aria-label': k('incompleta') }, replace, keep),
|
||||
unknown);
|
||||
}
|
||||
|
||||
/** «La password va solo a Instagram», with the true wording of each shell (spec §10.3). */
|
||||
export function passwordNote(windows) {
|
||||
return h('div.avviso.nota-password', icon('shield-check', 's'),
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"nessunAccount": "Nessun account",
|
||||
"verifica": "Verifica richiesta",
|
||||
"scollegato": "Sessione chiusa",
|
||||
"copiaMancante": "Serve «Ho finito»",
|
||||
"accountDaLeggere": "Nome non ancora noto",
|
||||
"nonDisponibile": "Stato del motore non disponibile"
|
||||
},
|
||||
@@ -690,9 +691,32 @@
|
||||
"stati": {
|
||||
"notConnected": "Non collegato",
|
||||
"connected": "Collegato",
|
||||
"copyMissing": "Serve «Ho finito»",
|
||||
"verificationRequired": "Verifica richiesta",
|
||||
"browserUnavailable": "Browser non disponibile"
|
||||
},
|
||||
"copiaMancanteTitolo": "Manca la copia della sessione",
|
||||
"copiaMancanteTesto": "Il browser è collegato, ma Febe non ha ancora una copia della sessione per le richieste (o non riesce a leggerla). Apri la tua pagina iniziale nel browser e premi «Ho finito»: fino ad allora il motore aspetta.",
|
||||
"salvata": {
|
||||
"titolo": "Sessione salvata per le richieste",
|
||||
"copiata": "Copiata {quando}.",
|
||||
"nessuna": "Nessuna copia: premi «Ho finito» sulla tua pagina iniziale.",
|
||||
"illeggibile": "C'è un file, ma Febe non riesce a leggerlo (un'altra chiave o un file rovinato): conta come nessuna copia. Il prossimo «Ho finito» lo sostituisce.",
|
||||
"valori": "Valori della pagina: {presenti} su {attesi}.",
|
||||
"docId": "doc_id: {presenti} su {attesi}.",
|
||||
"cookie": "Cookie: {n}.",
|
||||
"mancano": "Mancano: {nomi}.",
|
||||
"servono": "{n} di questi serve alle richieste configurate: le richieste che lo usano non partono e, alla prima, Febe si ferma come disconnessione.|{n} di questi servono alle richieste configurate: quelle richieste non partono e, alla prima, Febe si ferma come disconnessione.",
|
||||
"completa": "Nulla di ciò che le richieste configurate mandano manca.",
|
||||
"nota": "Qui ci sono solo conteggi e nomi, mai i valori.",
|
||||
"incompleta": "Se una copia nuova è incompleta",
|
||||
"sostituisci": "Sostituisci comunque (consigliato)",
|
||||
"sostituisciAiuto": "La copia nuova prende sempre il posto di quella salvata: una copia più vecchia potrebbe avere i cookie di un altro accesso.",
|
||||
"tieni": "Tieni la copia completa",
|
||||
"tieniAiuto": "Se alla copia nuova manca qualcosa che le richieste usano e quella salvata è completa, Febe tiene quella salvata e te lo dice.",
|
||||
"salvato": "Scelta salvata: vale dalla prossima copia.",
|
||||
"sceltaIgnota": "Febe non è riuscito a leggere la scelta salvata: scegline una per salvarla di nuovo."
|
||||
},
|
||||
"come": "Come collegarti",
|
||||
"passi": [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user