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

[Windows] Close the WebView2 disconnecting the Handler #12925

Closed
wants to merge 4 commits into from

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Jan 26, 2023

Description of Change

Changes:

  • Close the WebView2 disconnecting the Handler.
  • Invoke the WebView DisconnectHandler method closing a Window (if contains a WebView).

image

To test/validate the changes, open the .NET MAUI Gallery and navigate to the Core section. Select the MutiWindow demo and open a new Window. Then, close it. Without exceptions, the test passed. We are:

  • Correctly dispose the WebView disconnecting the handler.
  • Avoiding crash closing a Windows that contains a WebView.

Issues Fixed

Fixes #10436
Fixes #8323
Fixes #7317
Fixes #12956

@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jan 26, 2023
Comment on lines 187 to 190
#if WINDOWS
else if (propertyName == nameof(Window) && Window is not null)
Window.Destroying += OnWindowDestroying;
#endif
Copy link
Member

@mattleibow mattleibow Jan 27, 2023

Choose a reason for hiding this comment

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

This feels like the wrong place... or thing... no idea why just yet, but maybe I am feeling that some other event should go down the line when a window hosting a control is closed... Is there some Unloaded or some such event that gets to controls when a window is closed.

If I have a label in a window and close the window, do we have some event? Unloaded? The Window property goes null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mnn, yeah. I think that to have something simpler, we need a way to be able to have window change notifications from Handlers.

Copy link
Member

Choose a reason for hiding this comment

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

@jsuarezruiz @mattleibow can we get this agreed on so that we can land the PR?


namespace Microsoft.Maui.Controls
{
public partial class WebView
{
protected override void OnPropertyChanging(string? propertyName = null)
Copy link
Member

Choose a reason for hiding this comment

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

I think @PureWeen just added a WindowChanged event - and we may want to make that public. Maybe when a window is closing, we can propagate a Window = null change?

Copy link
Member

@mandel-macaque mandel-macaque left a comment

Choose a reason for hiding this comment

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

Approving, some small comments, wait or @mattleibow to comment in the event question.

src/Controls/src/Core/WebView.cs Outdated Show resolved Hide resolved
Comment on lines 187 to 190
#if WINDOWS
else if (propertyName == nameof(Window) && Window is not null)
Window.Destroying += OnWindowDestroying;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

@jsuarezruiz @mattleibow can we get this agreed on so that we can land the PR?

@rmarinho
Copy link
Member

rmarinho commented Feb 9, 2023

Closing this one as we merged another approach on the handler side #13206

@rmarinho rmarinho closed this Feb 9, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants