chromelyapps / Chromely

Build Cross Platform HTML Desktop Apps on .NET using native GUI, HTML5, JavaScript, CSS, Owin, AspNetCore (MVC, RazorPages, Blazor)
MIT License
2.99k stars 279 forks source link

Cancel native app close #391

Open wana211 opened 1 year ago

wana211 commented 1 year ago

Is it possible to cancel the native app being closed? I can see a "HostClose" event on IChromelyNativeHost but this doesn't let you cancel. Perhaps "CloseEventArgs" could have a cancel property?

I'm developing a Cross-Platform app and when the native form is closed I need to cancel and show a "Are you sure message?" in case they have outstanding changes to save.

I have tried the Frameless option but this appears to only be implemented on Windows?

mattkol commented 1 year ago

@DSEWayne I could not really find time to verify why 'HostClose" may not work because of the holidays. Are you able to verify that your code is being called?

wana211 commented 1 year ago

Hi, "HostClose" is being called and I can put code in there that is called upon close. I just can't see any way to cancel the close request. When the user closes the native app I want to be able to cancel the users close request if they have outstanding changes and prompt them with a HTML message box asking if they want to save before I allow the native app to be closed.

mattkol commented 1 year ago

@DSEWayne I think I get your point now. There was never really any consideration for the option to avoid closing. The method was meant primarily to allow cleanups and other utility work before closing. What you are trying to do can be done though with some customization at your end.

wana211 commented 1 year ago

Thanks, I thought that was the case. By "customization at your end" do you mean modifying the Chromely source code? Or can it be done another way? I have a local copy of the source code and I've added a Boolean "cancel" property to the event args passed into the "HostClose" event and this is working. I can create a fork and add my changes in there.