Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
55 lines
2.2 KiB
C#
55 lines
2.2 KiB
C#
using Febe.Core.Library;
|
|
using Febe.Web.Connection;
|
|
|
|
namespace Febe.App;
|
|
|
|
/// <summary>The problems found at start-up; fixed for the life of the process (fixing one needs a restart).</summary>
|
|
public sealed class StartupProblems(IReadOnlyList<ConfigurationProblem> problems) : IConfigurationProblems
|
|
{
|
|
public IReadOnlyList<ConfigurationProblem> Current { get; } = problems;
|
|
}
|
|
|
|
/// <summary>Checks shared by both shells (spec §8.2): the Data folder is local and writable.</summary>
|
|
public static class DataFolderProblems
|
|
{
|
|
public const string DataNotWritable = "dati-non-scrivibili";
|
|
|
|
public const string DataOnNetwork = "dati-in-rete";
|
|
|
|
/// <summary>The problem with the Data folder, or null when it is fine.</summary>
|
|
public static ConfigurationProblem? Check(string dataFolder, DataFolderCheck? check = null)
|
|
{
|
|
if ((check ?? new DataFolderCheck()).Check(dataFolder) is not { } data)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new ConfigurationProblem(
|
|
data.Kind == DataFolderProblemKind.NetworkPath ? DataOnNetwork : DataNotWritable,
|
|
data.Title,
|
|
data.Explanation,
|
|
data.Remedy);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The link to Instagram while a configuration problem keeps the browser from starting: always «browser non
|
|
/// disponibile», and every command refused with the problem (the configuration gate refuses them earlier anyway).
|
|
/// </summary>
|
|
public sealed class ProblemConnectionService(IReadOnlyList<ConfigurationProblem> problems) : IConnectionService
|
|
{
|
|
public Task<ConnectionStatus> GetStatusAsync(CancellationToken ct) =>
|
|
Task.FromResult(new ConnectionStatus(ConnectionState.BrowserUnavailable, null, null, false, null));
|
|
|
|
public Task BeginUserDrivingAsync(bool openLogin, CancellationToken ct) => throw Refused();
|
|
|
|
public Task<FinishResult> FinishAsync(CancellationToken ct) => throw Refused();
|
|
|
|
public Task CancelAsync(CancellationToken ct) => Task.CompletedTask;
|
|
|
|
public Task DisconnectAsync(CancellationToken ct) => throw Refused();
|
|
|
|
private Febe.Web.Api.BadRequestException Refused() =>
|
|
new($"{(problems.Count > 0 ? problems[0].Title : "Configurazione da sistemare")}: il browser di Febe non è partito.");
|
|
}
|