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,277 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using Febe.App;
|
||||
using Febe.Browser.Recipes;
|
||||
|
||||
namespace Febe.Desktop.Core;
|
||||
|
||||
/// <summary>
|
||||
/// How the browser of Instagram is hosted on Windows: the three attempts of S2, in the order of spec §6.6. The first is
|
||||
/// the default; the others are fallbacks Alberto chooses with <c>--browser</c> while testing S2 (docs/windows.md).
|
||||
/// </summary>
|
||||
public enum BrowserHosting
|
||||
{
|
||||
/// <summary>«finestra»: WebView2 in its own window «Browser di Febe», kept open but out of view, occlusion off.</summary>
|
||||
Window,
|
||||
|
||||
/// <summary>«composizione»: the same window, with WebView2 hosted as a DirectComposition visual.</summary>
|
||||
Composition,
|
||||
|
||||
/// <summary>«edge»: Microsoft Edge started as a process and driven like Chromium in Docker (ChromiumProcessHost).</summary>
|
||||
Edge,
|
||||
}
|
||||
|
||||
/// <summary>Italian names of <see cref="BrowserHosting"/>, for the command line, the setting and the log.</summary>
|
||||
public static class BrowserHostingNames
|
||||
{
|
||||
/// <summary>Setting key (table <c>setting</c>) of the hosting chosen with <c>--browser</c>; it stays for the next starts.</summary>
|
||||
public const string SettingKey = "desktop.browser";
|
||||
|
||||
public static string Name(BrowserHosting hosting) => hosting switch
|
||||
{
|
||||
BrowserHosting.Composition => "composizione",
|
||||
BrowserHosting.Edge => "edge",
|
||||
_ => "finestra",
|
||||
};
|
||||
|
||||
public static bool TryParse(string? text, out BrowserHosting hosting)
|
||||
{
|
||||
switch (text?.Trim().ToLowerInvariant())
|
||||
{
|
||||
case "finestra":
|
||||
hosting = BrowserHosting.Window;
|
||||
return true;
|
||||
case "composizione":
|
||||
hosting = BrowserHosting.Composition;
|
||||
return true;
|
||||
case "edge":
|
||||
hosting = BrowserHosting.Edge;
|
||||
return true;
|
||||
default:
|
||||
hosting = BrowserHosting.Window;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The folders Windows gives Febe by default (spec §12): tests pass their own.</summary>
|
||||
/// <param name="LocalAppData"><c>%LOCALAPPDATA%</c>.</param>
|
||||
/// <param name="Pictures">The user's Pictures folder («Immagini»).</param>
|
||||
public sealed record DesktopFolders(string LocalAppData, string Pictures)
|
||||
{
|
||||
/// <summary>The folders of the current user.</summary>
|
||||
public static DesktopFolders Current() => new(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify),
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures, Environment.SpecialFolderOption.DoNotVerify));
|
||||
|
||||
/// <summary>Default Data folder: <c>%LOCALAPPDATA%\Febe</c>.</summary>
|
||||
public string DefaultDataFolder => Path.Combine(LocalAppData, "Febe");
|
||||
|
||||
/// <summary>Default library: <c>Immagini\Febe</c>.</summary>
|
||||
public string DefaultLibraryFolder => Path.Combine(Pictures, "Febe");
|
||||
}
|
||||
|
||||
/// <summary>Configuration of the Windows application, from its command line (spec §12).</summary>
|
||||
public sealed record DesktopOptions
|
||||
{
|
||||
/// <summary>Data folder chosen with <c>--dati</c> (development, a second account); null: the recorded or default one.</summary>
|
||||
public string? DataFolder { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Library chosen with <c>--libreria</c> (tests on Windows, a second account): the default of the setting instead of
|
||||
/// <c>Immagini\Febe</c>. A folder chosen later in Impostazioni still wins.
|
||||
/// </summary>
|
||||
public string? LibraryFolder { get; init; }
|
||||
|
||||
/// <summary><c>--nascosto</c>: start with the icon in the notification area only (start with the computer).</summary>
|
||||
public bool StartHidden { get; init; }
|
||||
|
||||
/// <summary><c>--browser finestra|composizione|edge</c>: the hosting of S2, stored for the next starts.</summary>
|
||||
public BrowserHosting? Hosting { get; init; }
|
||||
|
||||
/// <summary><c>--sviluppo</c>: the developer tools of the interface window (never of the browser of Febe).</summary>
|
||||
public bool DeveloperTools { get; init; }
|
||||
|
||||
/// <summary>Development: the local test site (tools/Febe.SitoDiProva) instead of Instagram, for S1 and S2.</summary>
|
||||
public Uri? TestSite { get; init; }
|
||||
|
||||
/// <summary>Development: the «CDN» of the test site (default: 127.0.0.2, site port + 1).</summary>
|
||||
public Uri? TestCdn { get; init; }
|
||||
|
||||
/// <summary>Development, test site only: opens the site once at start-up so its session cookie exists.</summary>
|
||||
public bool TestSiteAutoLogin { get; init; }
|
||||
|
||||
/// <summary>Development: the first session after this delay instead of 2–10 minutes.</summary>
|
||||
public TimeSpan? FirstSessionDelay { get; init; }
|
||||
|
||||
/// <summary>The fixed DevTools port of Edge (fallback «edge» only), on 127.0.0.1.</summary>
|
||||
public int EdgeDebugPort { get; init; } = 9222;
|
||||
|
||||
/// <summary>Size of the page of the browser of Febe, always the same (spec §6.1).</summary>
|
||||
public int BrowserWidth { get; init; } = 1280;
|
||||
|
||||
public int BrowserHeight { get; init; } = 900;
|
||||
|
||||
/// <summary>The site the browser works on: Instagram, or the local test site in development.</summary>
|
||||
public CollectionSite Site => TestSite is { } site
|
||||
? CollectionSite.TestSite(site.Authority, (TestCdn ?? DefaultCdn(site)).Authority)
|
||||
: CollectionSite.Instagram;
|
||||
|
||||
/// <summary>The page «Accedi a Instagram» opens: the real login page, or a page of the test site.</summary>
|
||||
public string LoginUrl => TestSite is { } site ? new Uri(site, "/benvenuto").AbsoluteUri : "https://www.instagram.com/accounts/login/";
|
||||
|
||||
/// <summary>The options of the shared composition.</summary>
|
||||
public FebeAppOptions AppOptions(string dataFolder, DesktopFolders folders) => new()
|
||||
{
|
||||
DataFolder = dataFolder,
|
||||
LibraryFolder = LibraryFolder ?? folders.DefaultLibraryFolder,
|
||||
LibraryFolderFromSettings = true,
|
||||
ImportFolder = null,
|
||||
ZoneId = TimeZoneInfo.Local.Id,
|
||||
Zone = TimeZoneInfo.Local,
|
||||
Language = CultureInfo.CurrentUICulture.Name,
|
||||
Site = Site,
|
||||
LoginUrl = LoginUrl,
|
||||
TestSite = TestSite,
|
||||
TestSiteAutoLogin = TestSiteAutoLogin,
|
||||
FirstSessionDelay = FirstSessionDelay,
|
||||
};
|
||||
|
||||
private static Uri DefaultCdn(Uri site) => new UriBuilder(site) { Host = "127.0.0.2", Port = site.Port + 1, Path = "/" }.Uri;
|
||||
}
|
||||
|
||||
/// <summary>Reads the command line of Febe.exe. Nothing secret ever passes on it.</summary>
|
||||
public static class DesktopCommandLine
|
||||
{
|
||||
public const string Usage =
|
||||
"Uso: Febe.exe [--nascosto] [--dati cartella] [--libreria cartella] [--browser finestra|composizione|edge] [--sviluppo]\n"
|
||||
+ " [--sito-di-prova http://127.0.0.1:8481 [--cdn-di-prova http://127.0.0.2:8482] [--accesso-di-prova]] [--prima-sessione secondi]";
|
||||
|
||||
public static bool TryParse(string[] args, out DesktopOptions options, out string problem)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(args);
|
||||
options = new DesktopOptions();
|
||||
problem = string.Empty;
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var arg = args[i];
|
||||
string? Next() => i + 1 < args.Length ? args[++i] : null;
|
||||
switch (arg.ToLowerInvariant())
|
||||
{
|
||||
case "--nascosto":
|
||||
options = options with { StartHidden = true };
|
||||
break;
|
||||
case "--sviluppo":
|
||||
options = options with { DeveloperTools = true };
|
||||
break;
|
||||
case "--dati":
|
||||
{
|
||||
var text = Next();
|
||||
if (string.IsNullOrWhiteSpace(text) || !Path.IsPathFullyQualified(text))
|
||||
{
|
||||
problem = "Dopo --dati serve il percorso completo di una cartella.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { DataFolder = Path.GetFullPath(text) };
|
||||
break;
|
||||
}
|
||||
|
||||
case "--libreria":
|
||||
{
|
||||
var text = Next();
|
||||
if (string.IsNullOrWhiteSpace(text) || !Path.IsPathFullyQualified(text))
|
||||
{
|
||||
problem = "Dopo --libreria serve il percorso completo di una cartella.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { LibraryFolder = Path.GetFullPath(text) };
|
||||
break;
|
||||
}
|
||||
|
||||
case "--browser":
|
||||
{
|
||||
var text = Next();
|
||||
if (!BrowserHostingNames.TryParse(text, out var hosting))
|
||||
{
|
||||
problem = $"Valore non valido dopo --browser («{text}»): finestra, composizione oppure edge.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { Hosting = hosting };
|
||||
break;
|
||||
}
|
||||
|
||||
case "--sito-di-prova":
|
||||
case "--cdn-di-prova":
|
||||
{
|
||||
var text = Next();
|
||||
if (!TryLocalAddress(text, out var address))
|
||||
{
|
||||
problem = $"Indirizzo non valido dopo {arg} («{text}»): serve un indirizzo http di questo computer, per esempio http://127.0.0.1:8481.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = arg.Equals("--sito-di-prova", StringComparison.OrdinalIgnoreCase)
|
||||
? options with { TestSite = address }
|
||||
: options with { TestCdn = address };
|
||||
break;
|
||||
}
|
||||
|
||||
case "--accesso-di-prova":
|
||||
options = options with { TestSiteAutoLogin = true };
|
||||
break;
|
||||
case "--prima-sessione":
|
||||
{
|
||||
var text = Next();
|
||||
if (!int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out var seconds) || seconds is < 1 or > 3600)
|
||||
{
|
||||
problem = $"Valore non valido dopo --prima-sessione («{text}»): secondi fra 1 e 3600.";
|
||||
return false;
|
||||
}
|
||||
|
||||
options = options with { FirstSessionDelay = TimeSpan.FromSeconds(seconds) };
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
problem = $"Opzione sconosciuta: {arg}.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.TestSiteAutoLogin && options.TestSite is null)
|
||||
{
|
||||
problem = "--accesso-di-prova vale solo con --sito-di-prova: con Instagram l'accesso lo fa sempre Alberto, a mano.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.TestCdn is not null && options.TestSite is null)
|
||||
{
|
||||
problem = "--cdn-di-prova vale solo con --sito-di-prova.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The test site must be on this computer: the switch can never point the browser elsewhere.</summary>
|
||||
private static bool TryLocalAddress(string? text, out Uri address)
|
||||
{
|
||||
address = null!;
|
||||
if (!Uri.TryCreate(text, UriKind.Absolute, out var uri) || uri.Scheme != Uri.UriSchemeHttp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var local = uri.IsLoopback || (IPAddress.TryParse(uri.Host, out var ip) && IPAddress.IsLoopback(ip));
|
||||
if (!local)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
address = new Uri(uri.GetLeftPart(UriPartial.Authority) + "/");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user