Finestra di Febe: gli indirizzi esterni si aprono dopo il gestore di WebView2
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
3f222448ee
commit
2ef098226b
1 file changed
+9
-2
@@ -1,6 +1,7 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Threading;
|
||||||
using Microsoft.Web.WebView2.Core;
|
using Microsoft.Web.WebView2.Core;
|
||||||
using Microsoft.Web.WebView2.Wpf;
|
using Microsoft.Web.WebView2.Wpf;
|
||||||
|
|
||||||
@@ -120,7 +121,7 @@ internal sealed class MainWindow : Window
|
|||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
if (uri.Scheme is "http" or "https")
|
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")
|
else if (uri.Scheme is "http" or "https")
|
||||||
{
|
{
|
||||||
_ = _openOutside(uri);
|
OpenOutsideLater(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens <paramref name="uri"/> 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).
|
||||||
|
/// </summary>
|
||||||
|
private void OpenOutsideLater(Uri uri) => Dispatcher.InvokeAsync(() => _openOutside(uri), DispatcherPriority.Background);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user