using Febe.App;
using Febe.Core.Library;
using Febe.Web.Connection;
namespace Febe.Desktop.Core;
///
/// The checks made before anything starts on Windows (spec §8.2, §12): the Data folder is on a local disk and writable,
/// and the WebView2 runtime is installed (it is in Windows 11 and in almost every Windows 10). With a problem the engine
/// and the browser do not start.
///
public static class DesktopStartupChecks
{
public const string WebView2Missing = "webview2-assente";
/// The official page of the WebView2 runtime (Microsoft), with the Evergreen installer.
public const string WebView2DownloadPage = "https://developer.microsoft.com/microsoft-edge/webview2/";
///
/// Every problem found, in the order the error page shows them.
///
/// The Data folder.
///
/// The installed WebView2 runtime (CoreWebView2Environment.GetAvailableBrowserVersionString), null when missing.
///
/// The Data folder check (tests inject a mount table).
public static IReadOnlyList Run(string dataFolder, Func webView2Version, DataFolderCheck? check = null)
{
ArgumentNullException.ThrowIfNull(webView2Version);
var problems = new List();
if (DataFolderProblems.Check(dataFolder, check) is { } data)
{
problems.Add(data);
}
string? version;
try
{
version = webView2Version();
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
version = null;
}
if (string.IsNullOrWhiteSpace(version))
{
problems.Add(WebView2Problem());
}
return problems;
}
/// «Manca il runtime WebView2», with the link to the official page.
public static ConfigurationProblem WebView2Problem() => new(
WebView2Missing,
"Manca il runtime WebView2 di Microsoft",
"Febe mostra la sua interfaccia e apre Instagram con WebView2, il componente di Microsoft Edge che Windows 11 e "
+ "quasi tutti i Windows 10 hanno già. Su questo computer non c'è, quindi Febe non ha avviato né il motore né il browser.",
$"Installa il runtime WebView2 «Evergreen» dalla pagina ufficiale di Microsoft ({WebView2DownloadPage}), poi riavvia Febe. "
+ "Non servono permessi di amministratore e non cambia nulla nel tuo Edge.");
}