Files
Febe/src/Febe.App/IFebePlatform.cs
T

127 lines
6.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Febe.Browser.Recipes;
using Febe.Core.Abstractions;
using Febe.Core.Alerts;
using Febe.Core.Library;
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>
/// 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>
public sealed record FebePlatformContext(FebeAppOptions Options, DataFolderLayout Data, IFebeStorage Storage, IClock Clock, FebeLog Log, BrowserUseTracker Tracker);
/// <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>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>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; }
}