using Febe.App;
using Febe.Core.Library;
using Febe.Web;
using Febe.Web.Connection;
using Microsoft.Extensions.DependencyInjection;
namespace Febe.Server;
///
/// The Docker edition's parts of the composition (spec ยง11): password-protected interface on every address, the
/// password and the Data folder checked at start-up, Chromium on Xvfb supervised by Febe itself, the remote view of the
/// browser in the Collegamento and Browser pages. No native shell: folders are read-only in the interface.
///
internal sealed class DockerPlatform(ServerOptions options) : IFebePlatform
{
public ServerOptions Options { get; } = options ?? throw new ArgumentNullException(nameof(options));
public FebeWebOptions WebOptions => Options.WebOptions();
public FebeListen Listen => new(Options.ListenAddress, Options.Port);
/// The remote view of the browser, once the composition registered it.
public BrowserRemoteViewHost? RemoteView { get; private set; }
public IReadOnlyList CheckConfiguration(FebeAppOptions appOptions, DataFolderCheck dataFolderCheck) =>
StartupChecks.Run(Options, dataFolderCheck);
public Task CreateBrowserAsync(FebePlatformContext context, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(context);
var home = Path.Combine(context.Data.Root, "home");
return Task.FromResult(new ChromiumBrowser(
new ChromiumBrowserSettings
{
ProfileDirectory = context.Data.BrowserProfile,
HomeDirectory = home,
WindowWidth = Options.WindowWidth,
WindowHeight = Options.WindowHeight,
DebugPort = Options.DebugPort,
ExecutablePath = Options.ChromiumPath,
// Linux needs the virtual display; elsewhere (development on Windows) the browser opens a normal window.
Display = OperatingSystem.IsLinux() ? Options.Display : null,
Launch = Options.LaunchOptions(Path.GetFullPath(home)),
ReadyRemark = Options.NoSandbox ? ", senza sandbox (FEBE_SENZA_SANDBOX)" : null,
SandboxAdvice = " Se il registro parla della sandbox, vedi docs/docker.md: profilo seccomp oppure FEBE_SENZA_SANDBOX=1.",
},
context.Clock,
context.Log));
}
public void RegisterServices(IServiceCollection services, FebeApp app)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(app);
RemoteView = new BrowserRemoteViewHost(app.Browser!, app.Tracker, app.Clock, app.Log, openStartPage: ct => app.Connection?.OpenStartPageAsync(ct) ?? Task.CompletedTask);
services.AddSingleton(RemoteView);
}
public void RegisterProblemServices(IServiceCollection services, FebeApp app)
{
}
public Task StoppingAsync() => RemoteView?.ShutdownAsync() ?? Task.CompletedTask;
}