[Peek][Monaco Preview] Open Monaco URI in default browser (#27774)

* open Monaco URI in default browser

* added dialog when URI is opened
This commit is contained in:
Davide Giacometti
2023-08-21 15:51:29 +02:00
committed by GitHub
parent a46b80c76f
commit 7c7f6cabf7
4 changed files with 77 additions and 7 deletions

View File

@@ -157,6 +157,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
_webView.NavigationCompleted += WebView2Init;
_webView.Height = this.Height;
_webView.Width = this.Width;
_webView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
Controls.Add(_webView);
_webView.SendToBack();
_loadingBar.Value = 100;
@@ -218,6 +219,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
}
}
private async void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
{
// Monaco opens URI in a new window. We open the URI in the default web browser.
if (e.Uri != null && e.IsUserInitiated)
{
e.Handled = true;
await Launcher.LaunchUriAsync(new Uri(e.Uri));
}
}
/// <summary>
/// This event sets the height and width of the webview to the size of the form
/// </summary>