From 2ef098226b56316fa29aa42db4d30d683e209973 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Tue, 20 Oct 2026 10:30:20 +0200 Subject: [PATCH] Finestra di Febe: gli indirizzi esterni si aprono dopo il gestore di WebView2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La finestra dell'interfaccia apriva gli indirizzi esterni (guida, repository, «Apri su Instagram») nel browser predefinito dentro i gestori NavigationStarting e NewWindowRequested di WebView2. L'apertura passa dalla shell di Windows, che può far girare un ciclo di messaggi suo, e WebView2 non regge di essere richiamato dentro i propri gestori (modello dei thread di WebView2). Ora l'apertura si mette in coda sul thread dell'interfaccia e parte quando il gestore è tornato. Co-Authored-By: Claude Opus 5.5 --- src/Febe.Desktop/MainWindow.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Febe.Desktop/MainWindow.cs b/src/Febe.Desktop/MainWindow.cs index cf395fd..8dfb6ab 100644 --- a/src/Febe.Desktop/MainWindow.cs +++ b/src/Febe.Desktop/MainWindow.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Windows; using System.Windows.Media; +using System.Windows.Threading; using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.Wpf; @@ -120,7 +121,7 @@ internal sealed class MainWindow : Window e.Cancel = true; if (uri.Scheme is "http" or "https") { - _ = _openOutside(uri); + OpenOutsideLater(uri); } } @@ -138,7 +139,13 @@ internal sealed class MainWindow : Window } else if (uri.Scheme is "http" or "https") { - _ = _openOutside(uri); + OpenOutsideLater(uri); } } + + /// + /// Opens in Alberto's browser once the handler of WebView2's event has returned: the shell + /// may run a message loop of its own, and WebView2 does not support re-entering its handlers (threading model). + /// + private void OpenOutsideLater(Uri uri) => Dispatcher.InvokeAsync(() => _openOutside(uri), DispatcherPriority.Background); }