Browser mai bianco né muto: pagina iniziale, finestra che resta, fotogrammi che ripartono (#52)
Il browser di Febe a volte era bianco o non mostrava nulla. Le cause erano
diverse e si correggono insieme.
- Pagina iniziale. Se il browser è a riposo su about:blank e Alberto lo apre
(«Usa il browser», «Apri il browser»), Febe lo porta sulla home del sito
quando è collegato, altrimenti sulla pagina di accesso. È un'azione di
Alberto, sotto il suo permesso di guida, non del motore: Febe aspetta che
la sessione finisca e prende il turno della pagina.
Il nuovo pulsante «Pagina iniziale» sta nella barra della finestra di
Windows e nella vista remota. Su about:blank la barra dice «Il browser è a
riposo su una pagina vuota». «Indietro» non torna più sulla pagina di
riposo.
- Disconnessione. «Apri il browser» nella striscia rossa apre la pagina di
accesso. Con --accesso-di-prova il primo controllo all'avvio non segnala
più una disconnessione finta.
- Windows: la finestra resta.
- Lasciare una pagina di Febe non nasconde più la finestra «Browser di
Febe» e non la rimette a riposo: finisce solo il permesso tenuto dalla
pagina (cancel con pageLeft, IConnectionService.ReleaseAsync).
- Sullo schermo la finestra ha il suo pulsante nella barra delle
applicazioni, così ridurla a icona non la fa sparire. Dopo 2 minuti
ridotta a icona torna fuori vista (S2).
- Se lo schermo è troppo piccolo, la finestra si restringe all'area di
lavoro e la pagina si rimpicciolisce con ZoomFactor, con le stesse misure
CSS.
- I bordi della pagina si riapplicano, con NotifyParentWindowPositionChanged,
quando la finestra si mostra, si sposta o riparte il processo GPU.
- Una pagina che non risponde mentre Alberto guida resta com'è.
- IBrowserWindow.ShowAsync lascia il posto a
IConnectionService.ShowBrowserAsync.
- Docker: fotogrammi che ripartono. La vista remota ha un watchdog. Riavvia
i fotogrammi dopo una pagina nuova caricata senza fotogrammi e dopo circa
2 s di silenzio. L'attesa raddoppia fino a 30 s finché la pagina resta
ferma. Se il riavvio non porta nulla, la vista riceve un'immagine ferma
(Page.captureScreenshot, già fra i comandi ammessi).
RemoteViewSession ha ora un registro vero: avvii, riavvii e silenzi vanno
a livello Info, categoria «vista», senza indirizzi.
Se dopo 8 s non arriva nessuna immagine, l'interfaccia mostra «Nessuna
immagine dal browser» con «Riprova».
Nessun comando CDP nuovo e nessuna dipendenza nuova. Aggiornati PROTOCOLLO.md
e la guida (Primo collegamento, Attività e arresti, Installazione Windows,
Problemi comuni).
Prove nuove:
- ScreencastWatchdogTests, RemoteViewFramesTests (Chromium vero, solo CI
Linux)
- Home e Indietro in RemoteViewStartTests
- RemoteViewSocketTests
- ConnectionApiTests
- BrowserStartPageTests
- BrowserWindowDecisionTests e BrowserWindowTests (WebView2 vero)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65c0c4470e
commit
c49df4ca7b
49 files changed
+2056
-177
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Web.Connection;
|
||||
using Febe.Web.Engine;
|
||||
using Febe.Web.Native;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
@@ -36,9 +37,22 @@ public static class ConnectionApi
|
||||
return ApiHttp.Json(new FinishDto(result.Connected, result.Message), FebeJsonContext.Default.FinishDto);
|
||||
});
|
||||
|
||||
endpoints.MapPost("/api/connection/cancel", async (IConnectionService connection, CancellationToken ct) =>
|
||||
// «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).
|
||||
endpoints.MapPost("/api/connection/cancel", async (HttpContext context, IConnectionService connection, IBrowserWindow window, CancellationToken ct) =>
|
||||
{
|
||||
await connection.CancelAsync(ct).ConfigureAwait(false);
|
||||
var body = context.Request.ContentLength is null or > 0
|
||||
? await ApiHttp.BodyAsync(context, FebeJsonContext.Default.CancelDrivingRequest).ConfigureAwait(false)
|
||||
: new CancelDrivingRequest(false);
|
||||
if (body.PageLeft && window.IsSeparateWindow)
|
||||
{
|
||||
await connection.ReleaseAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await connection.CancelAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return Results.NoContent();
|
||||
});
|
||||
|
||||
|
||||
@@ -56,15 +56,19 @@ public static class EngineApi
|
||||
FebeJsonContext.Default.ResumeDto);
|
||||
});
|
||||
|
||||
// «Apri il browser» on Windows: the window of the browser comes to the front.
|
||||
endpoints.MapPost("/api/browser/show", async (IBrowserWindow browser, BrowserUseTracker tracker, IClock clock, CancellationToken ct) =>
|
||||
// «Apri il browser» on Windows: the window of the browser comes to the front, on the start page when it was at rest
|
||||
// and on the login page with { openLogin: true } (the red strip of a disconnection; issue #52).
|
||||
endpoints.MapPost("/api/browser/show", async (HttpContext context, IBrowserWindow browser, IConnectionService connection, BrowserUseTracker tracker, IClock clock, CancellationToken ct) =>
|
||||
{
|
||||
if (!browser.IsSeparateWindow)
|
||||
{
|
||||
throw new BadRequestException("Qui il browser di Febe si usa dalla pagina Browser.");
|
||||
}
|
||||
|
||||
await browser.ShowAsync(ct).ConfigureAwait(false);
|
||||
var body = context.Request.ContentLength is null or > 0
|
||||
? await ApiHttp.BodyAsync(context, FebeJsonContext.Default.BeginDrivingRequest).ConfigureAwait(false)
|
||||
: new BeginDrivingRequest(false);
|
||||
await connection.ShowBrowserAsync(body.OpenLogin, ct).ConfigureAwait(false);
|
||||
tracker.MarkUsed(clock.Now);
|
||||
return ApiHttp.Message("Il browser di Febe è in primo piano.");
|
||||
});
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Febe.Web.Api;
|
||||
[JsonSerializable(typeof(Library.LibraryChange))]
|
||||
[JsonSerializable(typeof(ConnectionStatusDto))]
|
||||
[JsonSerializable(typeof(BeginDrivingRequest))]
|
||||
[JsonSerializable(typeof(CancelDrivingRequest))]
|
||||
[JsonSerializable(typeof(FinishDto))]
|
||||
[JsonSerializable(typeof(IncidentListDto))]
|
||||
[JsonSerializable(typeof(AlertListDto))]
|
||||
|
||||
@@ -11,6 +11,12 @@ public sealed record ConnectionStatusDto(string State, string? Username, string?
|
||||
/// <summary><c>POST /api/connection/begin</c>.</summary>
|
||||
public sealed record BeginDrivingRequest(bool OpenLogin);
|
||||
|
||||
/// <summary>
|
||||
/// «Annulla», or the page that held the browser was left (<paramref name="PageLeft"/>): on Windows the window then
|
||||
/// stays as it is (issue #52).
|
||||
/// </summary>
|
||||
public sealed record CancelDrivingRequest(bool PageLeft);
|
||||
|
||||
/// <summary><c>POST /api/connection/finish</c>.</summary>
|
||||
public sealed record FinishDto(bool Connected, string Message);
|
||||
|
||||
|
||||
@@ -55,6 +55,21 @@ public interface IConnectionService
|
||||
/// <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>«Scollega» (after confirmation in the UI): stops the engine and deletes the browser profile.</summary>
|
||||
Task DisconnectAsync(CancellationToken ct);
|
||||
}
|
||||
@@ -8,16 +8,25 @@ 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 }` |
|
||||
| `POST /api/connection/begin` | `{ openLogin: bool }` → 204. Alberto usa il browser; con `openLogin` il browser carica la pagina di accesso vera |
|
||||
| `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` | → 204 («Annulla») |
|
||||
| `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) |
|
||||
| `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
|
||||
pagina di accesso. Aprirla dal riposo è un'azione di Alberto, sotto il suo permesso di guida (`UserIsDriving`), non
|
||||
del motore: Febe aspetta che la sessione del motore finisca, prende la pagina e solo dopo naviga. La striscia rossa
|
||||
di una disconnessione apre il browser con `openLogin: true` (in Docker la pagina Browser con `?accesso=1`).
|
||||
|
||||
In modalità dimostrativa la scena `scollegato` dà `notConnected`, la scena `fermo` dà `verificationRequired`.
|
||||
|
||||
L'interfaccia manda `cancel` 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). Dopo un «Ho finito» riuscito la pagina chiude la vista remota e non manda un nuovo `begin`.
|
||||
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).
|
||||
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`.
|
||||
|
||||
## Vista remota (`/api/vista`, solo veste Docker)
|
||||
|
||||
@@ -30,13 +39,23 @@ Dal server al browser di Alberto:
|
||||
all'apertura e a ogni cambio di indirizzo o dimensione (l'indirizzo senza parametri di ricerca);
|
||||
- messaggi binari: un fotogramma JPEG ciascuno (da `Page.startScreencast`), da disegnare su un `<canvas>`.
|
||||
|
||||
I fotogrammi non devono fermarsi in silenzio (issue #52). Il server li riavvia (`Page.stopScreencast` e
|
||||
`Page.startScreencast`) quando una pagina nuova si è caricata (`Page.loadEventFired`) senza che ne sia arrivato
|
||||
uno, e quando non ne arrivano da circa 2 s; l'attesa raddoppia a ogni riavvio senza esito, fino a 30 s, e torna a
|
||||
2 s quando i fotogrammi scorrono di nuovo o cambia la pagina. Se dopo un riavvio non arriva nulla, manda un'immagine
|
||||
ferma della pagina (`Page.captureScreenshot`) come messaggio binario come gli altri. Avvii, riavvii e silenzi vanno
|
||||
nel registro (livello Info, categoria `vista`), senza indirizzi né contenuti. L'interfaccia, se dopo 8 s
|
||||
dall'apertura non ha ancora un fotogramma, mostra «Nessuna immagine dal browser» con «Riprova», che riapre la vista.
|
||||
Sul riposo (`about:blank`) la barra dice «Il browser è a riposo su una pagina vuota» invece dell'indirizzo.
|
||||
|
||||
Dal browser di Alberto al server, solo messaggi di testo JSON:
|
||||
|
||||
- `{ "type": "mouse", "action": "move"|"down"|"up"|"wheel", "x": 0..1, "y": 0..1, "button": "left"|"right"|"middle", "deltaX": n, "deltaY": n, "clickCount": n }`
|
||||
con coordinate relative al fotogramma;
|
||||
- `{ "type": "key", "action": "down"|"up"|"char", "key": "a", "code": "KeyA", "text": "a", "modifiers": n }`
|
||||
(i tasti non si registrano mai, né sul server né nel browser di Alberto);
|
||||
- `{ "type": "navigate", "action": "back"|"reload" }`.
|
||||
- `{ "type": "navigate", "action": "back"|"reload"|"home" }`: «Indietro» (salta la pagina di riposo), «Ricarica»,
|
||||
«Pagina iniziale» (la pagina iniziale descritta sopra).
|
||||
|
||||
## Problemi di configurazione
|
||||
|
||||
|
||||
@@ -114,6 +114,12 @@ public enum RemoteViewNavigation
|
||||
|
||||
/// <summary>Reload the current page.</summary>
|
||||
Reload,
|
||||
|
||||
/// <summary>
|
||||
/// «Pagina iniziale» (issue #52): the site's home when connected, the login page when not connected or after a
|
||||
/// disconnection. Alberto's own navigation while he drives (rule 7), like the other two.
|
||||
/// </summary>
|
||||
Home,
|
||||
}
|
||||
|
||||
/// <summary>The browser is not available (starting, restarting, missing, or Febe stopped by a configuration problem).</summary>
|
||||
|
||||
@@ -321,6 +321,7 @@ public static class RemoteViewSocket
|
||||
{
|
||||
"back" => RemoteViewNavigation.Back,
|
||||
"reload" => RemoteViewNavigation.Reload,
|
||||
"home" => RemoteViewNavigation.Home,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
|
||||
@@ -19,5 +19,9 @@ public sealed class UnavailableConnectionService : IConnectionService
|
||||
|
||||
public Task CancelAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task ShowBrowserAsync(bool openLogin, CancellationToken ct) => throw new BadRequestException(Message);
|
||||
|
||||
public Task ReleaseAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task DisconnectAsync(CancellationToken ct) => throw new BadRequestException(Message);
|
||||
}
|
||||
@@ -385,8 +385,6 @@ public sealed class DemoShell(IHttpContextAccessor accessor, string root) : INat
|
||||
public Task<bool> GetAutostartAsync(CancellationToken ct) => Task.FromResult(true);
|
||||
|
||||
public Task SetAutostartAsync(bool enabled, CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task ShowAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>Files of the demo: the shared sample pictures. Videos have only their cover.</summary>
|
||||
|
||||
@@ -57,6 +57,10 @@ public sealed class DemoConnectionService(IHttpContextAccessor accessor, DemoWor
|
||||
|
||||
public Task CancelAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task ShowBrowserAsync(bool openLogin, CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task ReleaseAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task DisconnectAsync(CancellationToken ct) =>
|
||||
throw new BadRequestException("Dimostrazione: Febe non si scollega davvero. Nella versione vera ferma il motore e cancella il profilo del browser con la sessione.");
|
||||
}
|
||||
|
||||
@@ -75,17 +75,15 @@ public sealed class BrowserShell : INativeShell
|
||||
/// </summary>
|
||||
public interface IBrowserWindow
|
||||
{
|
||||
/// <summary>True when the browser is a window of its own (Windows): «Apri il browser» calls <see cref="ShowAsync"/>.</summary>
|
||||
/// <summary>
|
||||
/// True when the browser is a window of its own (Windows): «Apri il browser» asks the connection to bring it to the
|
||||
/// front (<c>IConnectionService.ShowBrowserAsync</c>), and leaving a Febe page leaves the window as it is.
|
||||
/// </summary>
|
||||
bool IsSeparateWindow { get; }
|
||||
|
||||
/// <summary>Brings the browser window to the front (Windows). The engine stays still while Alberto uses it.</summary>
|
||||
Task ShowAsync(CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>No browser window (Docker uses the Browser page; the demo has no browser).</summary>
|
||||
public sealed class NoBrowserWindow : IBrowserWindow
|
||||
{
|
||||
public bool IsSeparateWindow => false;
|
||||
|
||||
public Task ShowAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<!-- @license lucide-static v1.56.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-house"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8" />
|
||||
<path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 459 B |
@@ -248,7 +248,9 @@ function renderBanner(frame, state) {
|
||||
}
|
||||
},
|
||||
}, icon('rotate-cw'), t('arresto.riprendi'));
|
||||
const open = h('button.btn.primo', { type: 'button', onclick: openBrowser }, icon('app-window'), t('arresto.apriBrowser'));
|
||||
// After a disconnection the browser opens on the login page (issue #52); after a verification it stays as it is.
|
||||
const disconnected = Boolean(state.connection && state.connection.state === 'disconnected');
|
||||
const open = h('button.btn.primo', { type: 'button', onclick: () => openBrowser({ login: disconnected }) }, icon('app-window'), t('arresto.apriBrowser'));
|
||||
const box = h(`div.arresto${isError ? '' : '.ambra'}`, { role: 'alert' },
|
||||
icon(isError ? 'octagon-alert' : 'triangle-alert', 'l'),
|
||||
h('div.testo', h('b', banner.title), h('span', banner.message)),
|
||||
@@ -257,18 +259,22 @@ function renderBanner(frame, state) {
|
||||
fill(frame.bannerSlot, box);
|
||||
}
|
||||
|
||||
/** «Apri il browser»: on Windows the window comes to the front; in Docker the Browser page with the remote view. */
|
||||
export async function openBrowser() {
|
||||
/**
|
||||
* «Apri il browser»: on Windows the window comes to the front; in Docker the Browser page with the remote view. A
|
||||
* browser at rest opens its start page; with login (the red strip of a disconnection) the login page.
|
||||
*/
|
||||
export async function openBrowser({ login = false } = {}) {
|
||||
const openLogin = login === true;
|
||||
if (caps().browserWindow) {
|
||||
try {
|
||||
const result = await api('/api/browser/show', { method: 'POST' });
|
||||
const result = await api('/api/browser/show', { method: 'POST', body: { openLogin } });
|
||||
toast(result.message);
|
||||
refreshEngine();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
} else {
|
||||
navigate('/browser');
|
||||
navigate(openLogin ? '/browser?accesso=1' : '/browser');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ function drawActions(page, state) {
|
||||
}, icon('pause'), h('span.testo-btn', t('attivita.pausa')));
|
||||
page.actions(
|
||||
first,
|
||||
h('button.btn', { type: 'button', onclick: openBrowser, 'aria-label': t('attivita.apriBrowser') }, icon('app-window'), h('span.testo-btn', t('attivita.apriBrowser'))),
|
||||
h('button.btn', { type: 'button', onclick: () => openBrowser(), 'aria-label': t('attivita.apriBrowser') }, icon('app-window'), h('span.testo-btn', t('attivita.apriBrowser'))),
|
||||
diagnosticsButton(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// 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».
|
||||
// (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)
|
||||
// opens the login page.
|
||||
|
||||
import { api } from '../core/api.js';
|
||||
import { caps } from '../core/context.js';
|
||||
@@ -24,7 +26,8 @@ export default {
|
||||
}
|
||||
if (page.signal.aborted) return;
|
||||
const lease = drivingLease(page);
|
||||
lease.begin(false);
|
||||
const login = new URLSearchParams(location.search).get('accesso') === '1';
|
||||
lease.begin(login);
|
||||
const message = h('div', { 'aria-live': 'polite' });
|
||||
const done = async () => {
|
||||
const result = await finishDriving();
|
||||
@@ -40,7 +43,7 @@ export default {
|
||||
h('div.destra', h('button.btn.primo.grande', { type: 'button', onclick: done }, t('impostazioni.collegamento.hoFinito')))));
|
||||
fill(page.body, h('div.pagina-browser',
|
||||
message,
|
||||
windows ? windowPanel() : remoteView(page, { url: status && status.currentUrl, login: status && status.state === 'notConnected' }).element,
|
||||
windows ? windowPanel() : remoteView(page, { url: status && status.currentUrl, login: login || (status && status.state === 'notConnected') }).element,
|
||||
passwordNote(windows)));
|
||||
},
|
||||
};
|
||||
@@ -40,15 +40,16 @@ 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 — counts as «Annulla»: the browser goes back to the
|
||||
* empty page and the engine may work again.
|
||||
* 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.
|
||||
*/
|
||||
export function drivingLease(page) {
|
||||
let held = false;
|
||||
const release = (keepalive) => {
|
||||
if (!held) return;
|
||||
held = false;
|
||||
releasing = api('/api/connection/cancel', { method: 'POST', keepalive }).then(() => {}, () => {});
|
||||
releasing = api('/api/connection/cancel', { method: 'POST', body: { pageLeft: true }, keepalive }).then(() => {}, () => {});
|
||||
};
|
||||
const onHide = () => release(true);
|
||||
window.addEventListener('pagehide', onHide);
|
||||
|
||||
@@ -11,6 +11,14 @@ import { label } from '../core/ui.js';
|
||||
const BUTTONS = ['left', 'middle', 'right'];
|
||||
const MAC = /Mac|iPhone|iPad/.test(navigator.platform || '');
|
||||
|
||||
/** How long the view waits for the first image before saying that none comes (issue #52). */
|
||||
const FIRST_FRAME_WAIT = 8000;
|
||||
|
||||
/** The empty page the browser rests on: the bar says so instead of showing an address. */
|
||||
function isRest(url) {
|
||||
return !url || url === 'about:blank';
|
||||
}
|
||||
|
||||
function altGraph(e) {
|
||||
return Boolean(e.getModifierState && e.getModifierState('AltGraph'));
|
||||
}
|
||||
@@ -44,8 +52,9 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
const address = h('span.dati');
|
||||
const back = h('button.btn.nudo.solo', { type: 'button', 'aria-label': t('browser.indietro'), title: t('browser.indietro'), onclick: () => send({ type: 'navigate', action: 'back' }) }, icon('arrow-left'));
|
||||
const reload = h('button.btn.nudo.solo', { type: 'button', 'aria-label': t('browser.ricarica'), title: t('browser.ricarica'), onclick: () => send({ type: 'navigate', action: 'reload' }) }, icon('rotate-cw'));
|
||||
const home = h('button.btn.nudo.solo', { type: 'button', 'aria-label': t('browser.paginaIniziale'), title: t('browser.paginaInizialeAiuto'), onclick: () => send({ type: 'navigate', action: 'home' }) }, icon('house'));
|
||||
const bar = h('div.vista-barra',
|
||||
back, reload,
|
||||
back, reload, home,
|
||||
h('div.vista-indirizzo', { 'aria-label': t('browser.indirizzo') }, icon('lock', 's'), address),
|
||||
label(t('browser.vista')));
|
||||
const canvas = h('canvas.vista-schermo', { tabindex: '0', 'aria-label': t('browser.schermo'), hidden: true, width: '1280', height: '900' });
|
||||
@@ -56,10 +65,14 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
let socket = null;
|
||||
let closed = false;
|
||||
let frames = 0;
|
||||
// Each connection has its number: what a replaced socket still says is ignored.
|
||||
let generation = 0;
|
||||
let waiting = null;
|
||||
|
||||
function showAddress(value) {
|
||||
if (!value) {
|
||||
address.replaceChildren();
|
||||
if (isRest(value)) {
|
||||
// Never a white area without a word (issue #52): the bar says the browser is resting, «Pagina iniziale» leaves.
|
||||
fill(address, h('span.muto', t('browser.aRiposo')));
|
||||
return;
|
||||
}
|
||||
const clean = String(value).replace(/^https?:\/\//, '');
|
||||
@@ -85,16 +98,41 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
status.hidden = false;
|
||||
}
|
||||
|
||||
/** No image from the browser after a while (the view is open): said plainly, with «Riprova». */
|
||||
function noImage() {
|
||||
canvas.hidden = true;
|
||||
fill(status, h('div.vista-segnaposto',
|
||||
icon('image', 'l'),
|
||||
h('p', t('browser.nessunaImmagine')),
|
||||
h('button.btn', { type: 'button', onclick: connect }, icon('refresh-cw', 's'), t('browser.riprova'))));
|
||||
status.hidden = false;
|
||||
}
|
||||
|
||||
function send(message) {
|
||||
if (socket && socket.readyState === 1) socket.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
function stopWaiting() {
|
||||
if (waiting) clearTimeout(waiting);
|
||||
waiting = null;
|
||||
}
|
||||
|
||||
function connect() {
|
||||
if (closed) return;
|
||||
if (caps().demo) {
|
||||
placeholder();
|
||||
return;
|
||||
}
|
||||
generation += 1;
|
||||
const mine = generation;
|
||||
stopWaiting();
|
||||
if (socket) {
|
||||
// «Riprova» on an open view: the old socket goes, its close says nothing.
|
||||
const old = socket;
|
||||
socket = null;
|
||||
old.close();
|
||||
}
|
||||
frames = 0;
|
||||
fill(status, h('div.vista-segnaposto', icon('hourglass', 'l'), h('p', t('browser.collegamento'))));
|
||||
status.hidden = false;
|
||||
const scheme = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
@@ -104,8 +142,13 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
failure();
|
||||
return;
|
||||
}
|
||||
waiting = setTimeout(() => {
|
||||
waiting = null;
|
||||
if (mine === generation && !closed && frames === 0) noImage();
|
||||
}, FIRST_FRAME_WAIT);
|
||||
socket.binaryType = 'blob';
|
||||
socket.addEventListener('message', async (e) => {
|
||||
if (mine !== generation) return;
|
||||
if (typeof e.data === 'string') {
|
||||
try {
|
||||
const meta = JSON.parse(e.data);
|
||||
@@ -127,6 +170,7 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
bitmap.close();
|
||||
frames += 1;
|
||||
if (frames === 1) {
|
||||
stopWaiting();
|
||||
canvas.hidden = false;
|
||||
status.hidden = true;
|
||||
}
|
||||
@@ -135,6 +179,8 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
}
|
||||
});
|
||||
socket.addEventListener('close', () => {
|
||||
if (mine !== generation) return;
|
||||
stopWaiting();
|
||||
socket = null;
|
||||
if (!closed) failure();
|
||||
});
|
||||
@@ -220,6 +266,7 @@ export function remoteView(page, { url = null, login = false } = {}) {
|
||||
|
||||
function close() {
|
||||
closed = true;
|
||||
stopWaiting();
|
||||
document.removeEventListener('paste', onPaste);
|
||||
window.removeEventListener('blur', releaseAll);
|
||||
if (socket) socket.close();
|
||||
|
||||
@@ -832,6 +832,10 @@
|
||||
"segnapostoAccesso": "Qui compare la vera pagina di accesso di Instagram, caricata dal sito. Febe non la ridisegna e non la imita.",
|
||||
"indietro": "Indietro",
|
||||
"ricarica": "Ricarica",
|
||||
"paginaIniziale": "Pagina iniziale",
|
||||
"paginaInizialeAiuto": "Pagina iniziale: la home del sito se sei collegato, altrimenti la pagina di accesso",
|
||||
"aRiposo": "Il browser è a riposo su una pagina vuota: premi «Pagina iniziale».",
|
||||
"nessunaImmagine": "Nessuna immagine dal browser: la vista è aperta, ma la pagina non arriva. Premi «Riprova»; se resta così, guarda il registro.",
|
||||
"indirizzo": "Indirizzo della pagina",
|
||||
"collegamento": "Collegamento alla vista remota…",
|
||||
"nonRisponde": "La vista remota non risponde: il browser di Febe non è raggiungibile in questo momento.",
|
||||
|
||||
Reference in new issue
Block a user