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,144 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Web.WebView2.Wpf;
|
||||
|
||||
namespace Febe.Desktop;
|
||||
|
||||
/// <summary>
|
||||
/// The main window (spec §12): a WebView2 showing the interface served in this process on 127.0.0.1. It opens
|
||||
/// <c>/?gettone=…</c> once — the token of this start becomes an HttpOnly cookie and leaves the address — and never
|
||||
/// leaves the interface: any other address opens in Alberto's default browser. Its WebView2 has a user data folder of
|
||||
/// its own (<c>Dati\interfaccia</c>), separate from the browser of Instagram.
|
||||
/// </summary>
|
||||
internal sealed class MainWindow : Window
|
||||
{
|
||||
private readonly WebView2 _view;
|
||||
private readonly Uri _origin;
|
||||
private readonly Func<Uri, Task> _openOutside;
|
||||
private bool _allowClose;
|
||||
|
||||
public MainWindow(ImageSource? icon, string userDataFolder, Uri origin, bool developerTools, Func<Uri, Task> openOutside)
|
||||
{
|
||||
_origin = origin ?? throw new ArgumentNullException(nameof(origin));
|
||||
_openOutside = openOutside ?? throw new ArgumentNullException(nameof(openOutside));
|
||||
Title = "Febe";
|
||||
Icon = icon;
|
||||
var area = SystemParameters.WorkArea;
|
||||
Width = Math.Min(1440, area.Width * 0.92);
|
||||
Height = Math.Min(900, area.Height * 0.92);
|
||||
MinWidth = 380;
|
||||
MinHeight = 480;
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
Background = new SolidColorBrush(Color.FromRgb(0xF4, 0xF5, 0xF7));
|
||||
_view = new WebView2
|
||||
{
|
||||
CreationProperties = new CoreWebView2CreationProperties { UserDataFolder = userDataFolder },
|
||||
};
|
||||
Content = _view;
|
||||
DeveloperTools = developerTools;
|
||||
}
|
||||
|
||||
/// <summary>The developer tools of the interface (only with <c>--sviluppo</c>).</summary>
|
||||
public bool DeveloperTools { get; }
|
||||
|
||||
/// <summary>Raised when Alberto closes the window; the application decides (notification area or exit).</summary>
|
||||
public event EventHandler? CloseRequested;
|
||||
|
||||
/// <summary>Creates the WebView and opens the interface at <paramref name="first"/> (the address with the token).</summary>
|
||||
public async Task OpenAsync(Uri first)
|
||||
{
|
||||
await _view.EnsureCoreWebView2Async().ConfigureAwait(true);
|
||||
var core = _view.CoreWebView2;
|
||||
var s = core.Settings;
|
||||
s.AreDevToolsEnabled = DeveloperTools;
|
||||
s.IsPasswordAutosaveEnabled = false;
|
||||
s.IsGeneralAutofillEnabled = false;
|
||||
s.IsStatusBarEnabled = false;
|
||||
core.NavigationStarting += OnNavigationStarting;
|
||||
core.NewWindowRequested += OnNewWindowRequested;
|
||||
core.ProcessFailed += (_, e) =>
|
||||
{
|
||||
if (e.ProcessFailedKind is CoreWebView2ProcessFailedKind.RenderProcessExited or CoreWebView2ProcessFailedKind.RenderProcessUnresponsive)
|
||||
{
|
||||
core.Reload();
|
||||
}
|
||||
};
|
||||
core.Navigate(first.AbsoluteUri);
|
||||
}
|
||||
|
||||
/// <summary>Shows the window in front, restoring it if minimised.</summary>
|
||||
public void Present()
|
||||
{
|
||||
if (!IsVisible)
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
}
|
||||
|
||||
Activate();
|
||||
Topmost = true;
|
||||
Topmost = false;
|
||||
_view.Focus();
|
||||
}
|
||||
|
||||
/// <summary>Closes the window for good (Febe is stopping).</summary>
|
||||
public void CloseForGood()
|
||||
{
|
||||
_allowClose = true;
|
||||
Close();
|
||||
_view.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
if (!_allowClose)
|
||||
{
|
||||
e.Cancel = true;
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private bool IsInterface(Uri uri) =>
|
||||
uri.Scheme == _origin.Scheme && string.Equals(uri.Authority, _origin.Authority, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private void OnNavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e)
|
||||
{
|
||||
if (!Uri.TryCreate(e.Uri, UriKind.Absolute, out var uri) || IsInterface(uri) || uri.Scheme is "about" or "data")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The window shows only Febe: the guide, the repository, Instagram links open in Alberto's own browser.
|
||||
e.Cancel = true;
|
||||
if (uri.Scheme is "http" or "https")
|
||||
{
|
||||
_ = _openOutside(uri);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNewWindowRequested(object? sender, CoreWebView2NewWindowRequestedEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (!Uri.TryCreate(e.Uri, UriKind.Absolute, out var uri))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsInterface(uri))
|
||||
{
|
||||
_view.CoreWebView2.Navigate(uri.AbsoluteUri);
|
||||
}
|
||||
else if (uri.Scheme is "http" or "https")
|
||||
{
|
||||
_ = _openOutside(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user