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; /// /// 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 /// , the same for both. /// public interface IFebePlatform { /// Interface options: edition, access (password in Docker, per-start token on Windows), allowed hosts. FebeWebOptions WebOptions { get; } /// Where Kestrel listens (Docker: every address on 8480; Windows: 127.0.0.1 on a port chosen at start-up). FebeListen Listen { get; } /// /// 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. /// IReadOnlyList CheckConfiguration(FebeAppOptions options, DataFolderCheck dataFolderCheck); /// The browser of this shell. Called once, after the database is open and before the engine exists. Task CreateBrowserAsync(FebePlatformContext context, CancellationToken ct); /// /// 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. /// void RegisterServices(IServiceCollection services, FebeApp app); /// Services of this shell while a configuration problem keeps everything else still. void RegisterProblemServices(IServiceCollection services, FebeApp app); /// Called first when the composition stops (Docker: the open remote view is closed with its reason). Task StoppingAsync(); } /// What a platform gets to build its browser. /// The options of the composition. /// The Data folder (profile in ). /// The database (settings of the shell, e.g. the S2 hosting mode on Windows). /// The clock of the engine. /// The log. /// When Alberto last used the browser: the desktop window marks it when he uses and closes it. public sealed record FebePlatformContext(FebeAppOptions Options, DataFolderLayout Data, IFebeStorage Storage, IClock Clock, FebeLog Log, BrowserUseTracker Tracker); /// Options of the shared composition, filled by each shell from its own configuration. public sealed record FebeAppOptions { /// Data folder: database, browser profile, thumbnails, backups, log (Docker /dati; Windows %LOCALAPPDATA%\Febe). public required string DataFolder { get; init; } /// Library folder (Docker /libreria, fixed; Windows Immagini\Febe, the default of the setting). public required string LibraryFolder { get; init; } /// /// Windows: the library folder chosen in Impostazioni (stored in the database) wins over , /// which is only its default. Docker: false, the volume decides. /// public bool LibraryFolderFromSettings { get; init; } /// Docker: the read-only root of the import sources (/importa). Null: any folder, chosen with the picker. public string? ImportFolder { get; init; } /// Time zone of the engine, of file names and (Docker) of the browser. public string ZoneId { get; init; } = "Europe/Rome"; public TimeZoneInfo Zone { get; init; } = TimeZoneInfo.Local; /// Language of the browser, for the log (Docker: LANG; Windows: the language of the system). public string Language { get; init; } = "it_IT.UTF-8"; /// The site the browser works on: Instagram, or the local test site in development. public CollectionSite Site { get; init; } = CollectionSite.Instagram; /// The page «Accedi a Instagram» opens. public string LoginUrl { get; init; } = "https://www.instagram.com/accounts/login/"; /// Development: the local test site (only for the warning in the log). public Uri? TestSite { get; init; } /// Development, test site only: opens the site once at start-up so its session cookie exists. public bool TestSiteAutoLogin { get; init; } /// Development: the first session comes after this delay instead of 2–10 minutes. public TimeSpan? FirstSessionDelay { get; init; } /// Warnings found while reading the configuration, for the log. public IReadOnlyList Warnings { get; init; } = []; } /// Things tests (and only tests) replace in the composition. public sealed record FebeAppHooks { public IClock? Clock { get; init; } public IRandomSource? Random { get; init; } /// The Data folder check (tests inject a mount table with a network share). public DataFolderCheck? DataFolderCheck { get; init; } /// Console writer for the log; null: none (the desktop has no console). public TextWriter? Console { get; init; } /// How long the web host waits for open requests (events, remote view) when stopping. public TimeSpan ShutdownTimeout { get; init; } = TimeSpan.FromSeconds(3); /// Fake Telegram (tests never reach the real API). public HttpMessageHandler? TelegramHandler { get; init; } /// Fake free-space probe for the «Disco quasi pieno» alert. public IFreeSpaceProbe? FreeSpace { get; init; } }