Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Windows Open Links in Browser with Configurability #4680

Conversation

TanayParikh
Copy link
Contributor

Windows portion of #4338

Merges into: #4645

@TanayParikh TanayParikh added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Feb 14, 2022
@TanayParikh TanayParikh requested a review from a team as a code owner February 14, 2022 22:48
src/BlazorWebView/src/Maui/Windows/WinUIWebViewManager.cs Outdated Show resolved Hide resolved
var uri = new Uri(args.Uri);
if (uri.Host != "0.0.0.0" && _externalLinkMode == ExternalLinkMode.OpenInExternalBrowser)
{
_ = Launcher.LaunchUriAsync(uri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log errors thrown by these tasks or do they appear somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just searched through, there doesn't seem to be an existing logging mechanism. Is there a standardized mechanism we could use here (or perhaps #4441 would cover it?).

: base(webview, services, dispatcher, fileProvider, jsComponents, hostPageRelativePath)
{
_webview = webview;
_hostPageRelativePath = hostPageRelativePath;
_contentRootDir = contentRootDir;
_externalLinkMode = externalLinkMode;

_webview.CoreWebView2Initialized += Webview_CoreWebView2Initialized;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to unsubscribed when this type is disposed?

Copy link
Contributor Author

@TanayParikh TanayParikh Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression the lifecycle of the WinUIWebViewManager and the associated WebView2Control would be essentially the same, hence I didn't bother with unsubscribing (given if they get disposed at the same time then there shouldn't be any stray references preventing GC). This is in line with the current async lambda we have for Blazor.Start():

_webview.CoreWebView2.DOMContentLoaded += async (_, __) =>
{
await _webview.CoreWebView2!.ExecuteScriptAsync(@"
Blazor.start();
");
};

I can add it in if you think it'd be beneficial.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, instead of hooking the Initialized event at all, you can wait until we force initialization and then hook the events you actually want directly. Here's where we force initialization in the shared code: https://github.com/dotnet/maui/blob/main/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs#L93

Because presumably we want exactly this logic on WinForms and WPF as well. Launching the browser will be different between WinUI and non-WinUI, but that could be abstracted via a delegate or something.

: base(webview, services, dispatcher, fileProvider, jsComponents, hostPageRelativePath)
{
_webview = webview;
_hostPageRelativePath = hostPageRelativePath;
_contentRootDir = contentRootDir;
_externalLinkMode = externalLinkMode;

_webview.CoreWebView2Initialized += Webview_CoreWebView2Initialized;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, instead of hooking the Initialized event at all, you can wait until we force initialization and then hook the events you actually want directly. Here's where we force initialization in the shared code: https://github.com/dotnet/maui/blob/main/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs#L93

Because presumably we want exactly this logic on WinForms and WPF as well. Launching the browser will be different between WinUI and non-WinUI, but that could be abstracted via a delegate or something.

@TanayParikh TanayParikh merged commit 817166a into taparik/androidAnchorTagConfigurability Feb 15, 2022
@TanayParikh TanayParikh deleted the taparik/windowsAnchorTagConfigurability branch February 15, 2022 21:45
@TanayParikh
Copy link
Contributor Author

Thanks for the feedback, merged into #4645 and will address feedback there.

TanayParikh added a commit that referenced this pull request Feb 24, 2022
* Blazor Android Open Links in Browser with Configurability

* Blazor Windows Open Links in Browser with Configurability (#4680)

* Blazor Windows Open Links in Browser with Configurability

Windows portion of #4338

* TryCreate URI

* PR Feedback

(cherry picked from commit 35f637e)

* OnExternalNavigationStarting

* Pranav Points

* Event based approach

* Info -> EventArgs

* iOS & Mac Catalyst

* Fix WPF/Winforms Browser Start

* Winforms ExternalNavigationStarting

* PR Feedback

* Remove ordering dependency during property mapping

* @blowdart feedback

* @Eilon feedback
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants