Files
Febe/src/Febe.Desktop.Core/DesktopStartupChecks.cs
T

63 lines
2.6 KiB
C#

using Febe.App;
using Febe.Core.Library;
using Febe.Web.Connection;
namespace Febe.Desktop.Core;
/// <summary>
/// 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.
/// </summary>
public static class DesktopStartupChecks
{
public const string WebView2Missing = "webview2-assente";
/// <summary>The official page of the WebView2 runtime (Microsoft), with the Evergreen installer.</summary>
public const string WebView2DownloadPage = "https://developer.microsoft.com/microsoft-edge/webview2/";
/// <summary>
/// Every problem found, in the order the error page shows them.
/// </summary>
/// <param name="dataFolder">The Data folder.</param>
/// <param name="webView2Version">
/// The installed WebView2 runtime (<c>CoreWebView2Environment.GetAvailableBrowserVersionString</c>), null when missing.
/// </param>
/// <param name="check">The Data folder check (tests inject a mount table).</param>
public static IReadOnlyList<ConfigurationProblem> Run(string dataFolder, Func<string?> webView2Version, DataFolderCheck? check = null)
{
ArgumentNullException.ThrowIfNull(webView2Version);
var problems = new List<ConfigurationProblem>();
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;
}
/// <summary>«Manca il runtime WebView2», with the link to the official page.</summary>
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.");
}