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:
Claude committed 2026-10-13 21:50:25 +00:00
1 parent dc4d1fc738
commit b443adfa8b
73 files changed
+7914 -699

No files matched your search

+158
View File
@@ -0,0 +1,158 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
using Febe.App;
using Febe.Core.Alerts;
using Febe.Desktop.Core;
using Febe.Web.Native;
using Microsoft.Win32;
namespace Febe.Desktop;
/// <summary>
/// The native functions of Windows offered to the interface (spec §12): folder picker (<see cref="OpenFolderDialog"/>),
/// «Mostra nella cartella» (<c>explorer.exe /select,"…"</c>), addresses in the default browser (shell execute), Windows
/// notifications (balloon tips of the notification-area icon) and start with the computer
/// (<c>HKCU\…\Run</c>, value <c>Febe</c>). Paths and addresses never come from the page: the web layer resolves them.
/// </summary>
internal sealed class WindowsShell(Dispatcher ui, Func<Window?> owner, Func<TrayIcon?> tray) : INativeShell
{
public bool CanPickFolder => true;
public bool CanShowInFolder => true;
public bool CanOpenUrl => true;
public bool CanNotify => true;
public bool SupportsAutostart => true;
public Task<string?> PickFolderAsync(string title, string? initialFolder, CancellationToken ct) =>
ui.InvokeAsync(() =>
{
var dialog = new OpenFolderDialog { Title = title, Multiselect = false };
if (!string.IsNullOrWhiteSpace(initialFolder) && Directory.Exists(initialFolder))
{
dialog.InitialDirectory = initialFolder;
}
var window = owner();
var chosen = window is { IsVisible: true } ? dialog.ShowDialog(window) : dialog.ShowDialog();
return chosen == true ? dialog.FolderName : null;
}).Task;
public Task<bool> ShowInFolderAsync(string fullPath, CancellationToken ct)
{
if (string.IsNullOrWhiteSpace(fullPath) || !Path.IsPathFullyQualified(fullPath) || fullPath.Contains('"', StringComparison.Ordinal) || !File.Exists(fullPath))
{
return Task.FromResult(false);
}
var explorer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
try
{
using var process = Process.Start(new ProcessStartInfo(explorer, $"/select,\"{fullPath}\"") { UseShellExecute = false });
return Task.FromResult(process is not null);
}
catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidOperationException)
{
return Task.FromResult(false);
}
}
public Task<bool> OpenUrlAsync(Uri address, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(address);
if (!address.IsAbsoluteUri || address.Scheme is not ("http" or "https"))
{
return Task.FromResult(false);
}
try
{
// The default browser of Alberto (never the browser of Febe), through the shell.
using var process = Process.Start(new ProcessStartInfo(address.AbsoluteUri) { UseShellExecute = true });
return Task.FromResult(true);
}
catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidOperationException)
{
return Task.FromResult(false);
}
}
public Task NotifyAsync(string title, string message, CancellationToken ct) =>
ui.InvokeAsync(() => tray()?.Notify(title, message)).Task;
public Task<bool> GetAutostartAsync(CancellationToken ct)
{
using var key = Registry.CurrentUser.OpenSubKey(Autostart.RunKey, writable: false);
var value = key?.GetValue(Autostart.ValueName) as string;
return Task.FromResult(Environment.ProcessPath is { } exe && Autostart.PointsTo(value, exe));
}
public Task SetAutostartAsync(bool enabled, CancellationToken ct)
{
using var key = Registry.CurrentUser.CreateSubKey(Autostart.RunKey, writable: true);
if (enabled)
{
var exe = Environment.ProcessPath ?? throw new InvalidOperationException("Percorso di Febe.exe sconosciuto.");
key.SetValue(Autostart.ValueName, Autostart.Command(exe), RegistryValueKind.String);
}
else
{
key.DeleteValue(Autostart.ValueName, throwOnMissingValue: false);
}
return Task.CompletedTask;
}
}
/// <summary>Windows notifications for the alerts of spec §13.3 (Impostazioni ▸ Notifiche ▸ «Notifiche di Windows»).</summary>
internal sealed class WindowsNotificationChannel(Dispatcher ui, Func<TrayIcon?> tray) : IAlertChannel
{
public bool IsEnabled(AlertSettings settings) => settings?.WindowsNotifications == true;
public Task SendAsync(FebeAlert alert, AlertSettings settings, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(alert);
var warning = alert.Kind is AlertKind.Verification or AlertKind.Disconnection or AlertKind.Throttle or AlertKind.DiskLow;
return ui.InvokeAsync(() => tray()?.Notify(alert.Title, alert.Message, warning)).Task;
}
}
/// <summary>
/// The Data folder in use after a move, and a move asked for the next start (<see cref="DataFolderMove"/>), under
/// <c>HKCU\Software\Febe</c>: values «CartellaDati» and «NuovaCartellaDati». The uninstaller reads the first to say
/// where the data are.
/// </summary>
internal sealed class RegistryLocationStore : IDataFolderLocationStore
{
public const string Key = @"Software\Febe";
public string? Current => Read("CartellaDati");
public string? Pending => Read("NuovaCartellaDati");
public void SetCurrent(string? folder) => Write("CartellaDati", folder);
public void SetPending(string? folder) => Write("NuovaCartellaDati", folder);
private static string? Read(string name)
{
using var key = Registry.CurrentUser.OpenSubKey(Key, writable: false);
return key?.GetValue(name) is string value && !string.IsNullOrWhiteSpace(value) ? value : null;
}
private static void Write(string name, string? value)
{
using var key = Registry.CurrentUser.CreateSubKey(Key, writable: true);
if (value is null)
{
key.DeleteValue(name, throwOnMissingValue: false);
}
else
{
key.SetValue(name, value, RegistryValueKind.String);
}
}
}