M6 Windows: composizione condivisa Febe.App per Server e Desktop; Febe per Windows (WPF) con l'interfaccia in WebView2, area di notifica, istanza unica, «Browser di Febe» su WebView2 con CDP filtrato (WebView2CdpSession) e ripieghi di S2 (composizione, Edge), guscio nativo, avvisi, spostamento verificato della cartella dei dati, icona del marchio; un solo Febe.exe, installatore NSIS e zip portabile; guida docs/windows.md e prove dal vivo S1–S3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
73 files changed
+7914
-699
No files matched your search
@@ -0,0 +1,123 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Febe.App;
|
||||
using Febe.Desktop.Core;
|
||||
using Febe.Tests.Support;
|
||||
|
||||
namespace Febe.Tests.Desktop.Support;
|
||||
|
||||
/// <summary>
|
||||
/// The Windows composition on Linux: the shared <see cref="FebeApp"/> with the real <see cref="DesktopPlatform"/>
|
||||
/// (token of this start, 127.0.0.1 on a port chosen at start-up, start-up checks, hosting of S2, native services) and
|
||||
/// a fake of the Windows-only part (<see cref="FakeDesktopShell"/>). Data and library in a temporary folder; the
|
||||
/// interface is asked like the main window asks it, with the token and the Origin of the interface.
|
||||
/// </summary>
|
||||
internal sealed class DesktopTestBed : IAsyncDisposable
|
||||
{
|
||||
private readonly bool _ownsTemp;
|
||||
|
||||
private DesktopTestBed(TempFolder temp, bool ownsTemp, FakeDesktopShell shell, MemoryLocationStore locations, DesktopPlatform platform, FebeApp app)
|
||||
{
|
||||
Temp = temp;
|
||||
_ownsTemp = ownsTemp;
|
||||
Shell = shell;
|
||||
Locations = locations;
|
||||
Platform = platform;
|
||||
App = app;
|
||||
Client = new HttpClient(new HttpClientHandler { UseCookies = false, AllowAutoRedirect = false }) { BaseAddress = app.Address, Timeout = TimeSpan.FromSeconds(30) };
|
||||
}
|
||||
|
||||
public TempFolder Temp { get; }
|
||||
|
||||
public FakeDesktopShell Shell { get; }
|
||||
|
||||
public MemoryLocationStore Locations { get; }
|
||||
|
||||
public DesktopPlatform Platform { get; }
|
||||
|
||||
public FebeApp App { get; }
|
||||
|
||||
public HttpClient Client { get; }
|
||||
|
||||
public DesktopFolders Folders => new(Temp.Combine("AppData", "Local"), Temp.Combine("Immagini"));
|
||||
|
||||
/// <summary>The fake window «Browser di Febe» (null with a configuration problem or with Edge).</summary>
|
||||
public FakeBrowser? Browser => App.Browser as FakeBrowser;
|
||||
|
||||
public string Origin => $"{App.Address.Scheme}://{App.Address.Authority}";
|
||||
|
||||
public static async Task<DesktopTestBed> StartAsync(string[]? args = null, FakeDesktopShell? shell = null, TempFolder? temp = null, MemoryLocationStore? locations = null)
|
||||
{
|
||||
var ownsTemp = temp is null;
|
||||
temp ??= new TempFolder("desktop");
|
||||
shell ??= new FakeDesktopShell();
|
||||
locations ??= new MemoryLocationStore();
|
||||
if (!DesktopCommandLine.TryParse(args ?? [], out var options, out var problem))
|
||||
{
|
||||
throw new ArgumentException(problem);
|
||||
}
|
||||
|
||||
var folders = new DesktopFolders(temp.Combine("AppData", "Local"), temp.Combine("Immagini"));
|
||||
var platform = new DesktopPlatform(options, shell, locations, dataFolderFixed: options.DataFolder is not null);
|
||||
var app = await FebeApp.StartAsync(options.AppOptions(options.DataFolder ?? folders.DefaultDataFolder, folders), platform, new FebeAppHooks { ShutdownTimeout = TimeSpan.FromSeconds(1) });
|
||||
return new DesktopTestBed(temp, ownsTemp, shell, locations, platform, app);
|
||||
}
|
||||
|
||||
/// <summary>A request as the main window sends it: the token (here as the header the cookie stands for) and the Origin.</summary>
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpMethod method, string path, string? json = null, bool token = true)
|
||||
{
|
||||
using var request = new HttpRequestMessage(method, path);
|
||||
if (token)
|
||||
{
|
||||
request.Headers.TryAddWithoutValidation(Febe.Web.Security.AccessToken.HeaderName, Platform.AccessToken);
|
||||
}
|
||||
|
||||
request.Headers.TryAddWithoutValidation("Origin", Origin);
|
||||
if (json is not null)
|
||||
{
|
||||
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
}
|
||||
|
||||
return await Client.SendAsync(request);
|
||||
}
|
||||
|
||||
public async Task<JsonElement> JsonAsync(HttpMethod method, string path, string? json = null)
|
||||
{
|
||||
using var response = await SendAsync(method, path, json);
|
||||
var text = await response.Content.ReadAsStringAsync();
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, $"{path}: {text}");
|
||||
return JsonDocument.Parse(text).RootElement.Clone();
|
||||
}
|
||||
|
||||
public static async Task WaitUntilAsync(Func<bool> condition, TimeSpan timeout, string what)
|
||||
{
|
||||
var deadline = DateTime.UtcNow + timeout;
|
||||
while (!condition())
|
||||
{
|
||||
if (DateTime.UtcNow > deadline)
|
||||
{
|
||||
Assert.Fail($"Tempo scaduto: {what}.");
|
||||
}
|
||||
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Stops the composition; the folders stay for a second start (dispose <see cref="Temp"/> at the end).</summary>
|
||||
public async ValueTask StopAsync()
|
||||
{
|
||||
Client.Dispose();
|
||||
await App.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Stops; deletes the temporary folder only when the bed created it (a shared one is the caller's).</summary>
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await StopAsync();
|
||||
if (_ownsTemp)
|
||||
{
|
||||
Temp.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user