«Avviala dalla selezione» mandava a una selezione che saltava il video; un file in due account si cercava solo nel primo; un avvio di video già in coda sembrava una ricerca nuova; una lettura ferma bloccava la chiusura di Febe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
183 lines
9.6 KiB
C#
183 lines
9.6 KiB
C#
using Febe.Browser.Recipes;
|
||
using Febe.Core.Abstractions;
|
||
using Febe.Core.Alerts;
|
||
using Febe.Core.Export;
|
||
using Febe.Core.Library;
|
||
using Febe.Core.Security;
|
||
using Febe.Core.Storage;
|
||
using Febe.Web;
|
||
using Febe.Web.Connection;
|
||
using Febe.Web.Engine;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
|
||
namespace Febe.App;
|
||
|
||
/// <summary>
|
||
/// The parts of a shell that differ between Docker and Windows (spec §5 «I due involucri»): how the interface is
|
||
/// protected and where it listens, which checks stop the engine at start-up, which browser visits the site and how it
|
||
/// is supervised, and the native services (folder picker, notifications, remote view…). Everything else — database,
|
||
/// library, import, backups, collection pipeline, downloads, engine, connection, alerts, web host — is
|
||
/// <see cref="FebeApp"/>, the same for both.
|
||
/// </summary>
|
||
public interface IFebePlatform
|
||
{
|
||
/// <summary>Interface options: edition, access (password in Docker, per-start token on Windows), allowed hosts.</summary>
|
||
FebeWebOptions WebOptions { get; }
|
||
|
||
/// <summary>Where Kestrel listens (Docker: every address on 8480; Windows: 127.0.0.1 on a port chosen at start-up).</summary>
|
||
FebeListen Listen { get; }
|
||
|
||
/// <summary>
|
||
/// Problems that keep the engine and the browser from starting (spec §8.2, §11, §12). With any, only the interface
|
||
/// starts, on a temporary database, and shows the page that explains them.
|
||
/// </summary>
|
||
IReadOnlyList<ConfigurationProblem> CheckConfiguration(FebeAppOptions options, DataFolderCheck dataFolderCheck);
|
||
|
||
/// <summary>The browser of this shell. Called once, after the database is open and before the engine exists.</summary>
|
||
Task<IFebeBrowser> CreateBrowserAsync(FebePlatformContext context, CancellationToken ct);
|
||
|
||
/// <summary>
|
||
/// How this shell encrypts the saved session (issue #36, S4, spec §13.2): DPAPI for the current user on Windows,
|
||
/// AES-256-GCM in Docker with the key of <c>FEBE_CHIAVE_SESSIONE</c> or <c>Dati/sessione/chiave.bin</c>. Called at
|
||
/// most once, after the database is open, and only when the composition keeps a saved session
|
||
/// (<see cref="FebeAppOptions.Collection"/> is <see cref="CollectionRoute.Requests"/>). Says in the log where the
|
||
/// key comes from, never the key.
|
||
/// </summary>
|
||
/// <exception cref="InvalidDataException">The key file is there but is not a key of Febe.</exception>
|
||
/// <exception cref="IOException">The key file could not be made or read.</exception>
|
||
ISessionProtector CreateSessionProtector(FebePlatformContext context);
|
||
|
||
/// <summary>
|
||
/// Services of this shell for a normal start, registered before the web layer (whose fallbacks use TryAdd):
|
||
/// native shell (its notifications are the Windows channel of the alerts), browser window, remote view, change of
|
||
/// the Data folder.
|
||
/// </summary>
|
||
void RegisterServices(IServiceCollection services, FebeApp app);
|
||
|
||
/// <summary>Services of this shell while a configuration problem keeps everything else still.</summary>
|
||
void RegisterProblemServices(IServiceCollection services, FebeApp app);
|
||
|
||
/// <summary>Called first when the composition stops (Docker: the open remote view is closed with its reason).</summary>
|
||
Task StoppingAsync();
|
||
}
|
||
|
||
/// <summary>What a platform gets to build its browser.</summary>
|
||
/// <param name="Options">The options of the composition.</param>
|
||
/// <param name="Data">The Data folder (profile in <see cref="DataFolderLayout.BrowserProfile"/>).</param>
|
||
/// <param name="Storage">The database (settings of the shell, e.g. the S2 hosting mode on Windows).</param>
|
||
/// <param name="Clock">The clock of the engine.</param>
|
||
/// <param name="Log">The log.</param>
|
||
/// <param name="Tracker">When Alberto last used the browser: the desktop window marks it when he uses and closes it.</param>
|
||
/// <param name="OpenStartPage">
|
||
/// What «Pagina iniziale» of the browser window does (issue #52): the connection opens the site's home when connected,
|
||
/// the login page otherwise, once the engine's session ended and with the page's turn
|
||
/// (<c>BrowserConnectionService.OpenStartPageAsync</c>). Null: the button does nothing.
|
||
/// </param>
|
||
/// <param name="CopyOnWindowClosed">
|
||
/// What closing the browser window (or leaving it minimised too long) does before the page goes back to the engine
|
||
/// (issue #36, S4b): the connection copies the session into the saved session, when there is one
|
||
/// (<c>BrowserConnectionService.CopyOnWindowClosedAsync</c>). The window holds the driving gate until the task ends.
|
||
/// Null: nothing.
|
||
/// </param>
|
||
public sealed record FebePlatformContext(FebeAppOptions Options, DataFolderLayout Data, IFebeStorage Storage, IClock Clock, FebeLog Log, BrowserUseTracker Tracker, Func<CancellationToken, Task>? OpenStartPage = null, Func<BrowserWindowLetGo, CancellationToken, Task>? CopyOnWindowClosed = null);
|
||
|
||
/// <summary>How Alberto let go of the window «Browser di Febe» without «Ho finito» (Windows): the log says which.</summary>
|
||
public enum BrowserWindowLetGo
|
||
{
|
||
/// <summary>He closed it.</summary>
|
||
Closed,
|
||
|
||
/// <summary>He left it minimised longer than its limit: it went out of view as if closed.</summary>
|
||
MinimizedTooLong,
|
||
}
|
||
|
||
/// <summary>Options of the shared composition, filled by each shell from its own configuration.</summary>
|
||
public sealed record FebeAppOptions
|
||
{
|
||
/// <summary>Data folder: database, browser profile, thumbnails, backups, log (Docker /dati; Windows %LOCALAPPDATA%\Febe).</summary>
|
||
public required string DataFolder { get; init; }
|
||
|
||
/// <summary>Library folder (Docker /libreria, fixed; Windows Immagini\Febe, the default of the setting).</summary>
|
||
public required string LibraryFolder { get; init; }
|
||
|
||
/// <summary>
|
||
/// Windows: the library folder chosen in Impostazioni (stored in the database) wins over <see cref="LibraryFolder"/>,
|
||
/// which is only its default. Docker: false, the volume decides.
|
||
/// </summary>
|
||
public bool LibraryFolderFromSettings { get; init; }
|
||
|
||
/// <summary>Docker: the read-only root of the import sources (/importa). Null: any folder, chosen with the picker.</summary>
|
||
public string? ImportFolder { get; init; }
|
||
|
||
/// <summary>
|
||
/// Where the copies to external folders may go (spec §4.10, tappa E2). Docker: the subfolders of /esporta, and only
|
||
/// when declared (<c>--esporta</c>) and mounted. Windows: any folder, chosen with the picker.
|
||
/// </summary>
|
||
public ExportRootOptions ExportRoot { get; init; } = ExportRootOptions.AnyFolder;
|
||
|
||
/// <summary>Time zone of the engine, of file names and (Docker) of the browser.</summary>
|
||
public string ZoneId { get; init; } = "Europe/Rome";
|
||
|
||
public TimeZoneInfo Zone { get; init; } = TimeZoneInfo.Local;
|
||
|
||
/// <summary>Language of the browser, for the log (Docker: LANG; Windows: the language of the system).</summary>
|
||
public string Language { get; init; } = "it_IT.UTF-8";
|
||
|
||
/// <summary>The site the browser works on: Instagram, or the local test site in development.</summary>
|
||
public CollectionSite Site { get; init; } = CollectionSite.Instagram;
|
||
|
||
/// <summary>The page «Accedi a Instagram» opens.</summary>
|
||
public string LoginUrl { get; init; } = "https://www.instagram.com/accounts/login/";
|
||
|
||
/// <summary>Development: the local test site (only for the warning in the log).</summary>
|
||
public Uri? TestSite { get; init; }
|
||
|
||
/// <summary>Development, test site only: opens the site once at start-up so its session cookie exists.</summary>
|
||
public bool TestSiteAutoLogin { get; init; }
|
||
|
||
/// <summary>Development: the first session comes after this delay instead of 2–10 minutes.</summary>
|
||
public TimeSpan? FirstSessionDelay { get; init; }
|
||
|
||
/// <summary>
|
||
/// Option «raccolta» (issue #36, S4): <see cref="CollectionRoute.Pages"/> by default, as before S4.
|
||
/// <see cref="CollectionRoute.Requests"/> builds the saved session and the site client only when the site's catalog
|
||
/// has configured operations.
|
||
/// </summary>
|
||
public CollectionRoute Collection { get; init; } = CollectionRoute.Pages;
|
||
|
||
/// <summary>Warnings found while reading the configuration, for the log.</summary>
|
||
public IReadOnlyList<string> Warnings { get; init; } = [];
|
||
}
|
||
|
||
/// <summary>Things tests (and only tests) replace in the composition.</summary>
|
||
public sealed record FebeAppHooks
|
||
{
|
||
public IClock? Clock { get; init; }
|
||
|
||
public IRandomSource? Random { get; init; }
|
||
|
||
/// <summary>The Data folder check (tests inject a mount table with a network share).</summary>
|
||
public DataFolderCheck? DataFolderCheck { get; init; }
|
||
|
||
/// <summary>Console writer for the log; null: none (the desktop has no console).</summary>
|
||
public TextWriter? Console { get; init; }
|
||
|
||
/// <summary>How long the web host waits for open requests (events, remote view) when stopping.</summary>
|
||
public TimeSpan ShutdownTimeout { get; init; } = TimeSpan.FromSeconds(3);
|
||
|
||
/// <summary>Fake Telegram (tests never reach the real API).</summary>
|
||
public HttpMessageHandler? TelegramHandler { get; init; }
|
||
|
||
/// <summary>Fake free-space probe for the «Disco quasi pieno» alert.</summary>
|
||
public IFreeSpaceProbe? FreeSpace { get; init; }
|
||
|
||
/// <summary>Fake mount table for /esporta (it replaces the one of <see cref="FebeAppOptions.ExportRoot"/>).</summary>
|
||
public IExportMounts? ExportMounts { get; init; }
|
||
|
||
/// <summary>Fake free space and file size limit of the export folders.</summary>
|
||
public IExportDisk? ExportDisk { get; init; }
|
||
|
||
/// <summary>Fake analysis of «Video fermi» (a file that does not answer while Febe closes).</summary>
|
||
public Func<string, TimeSpan, CancellationToken, StillVideoResult>? StillVideoAnalyser { get; init; }
|
||
}
|