Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to Catch WebUI Window Close Event from System Menu 'Close' Button?

Post Reply
flydev
Posts: 6
Joined: Thu Oct 06, 2022 6:02 pm

How to Catch WebUI Window Close Event from System Menu 'Close' Button?

Post by flydev »

Hi @salvador, great project again 👌

On a Delphi or Lazarus project and I'm trying to catch the web_exit event when the user closes the WebUI window via the system menu (close button in the window's title bar).

Catching web_exit through a button in the JS interface works perfectly, but when the close button in the system menu is used, the event isn't triggered. I mean, If we take the sample `call_js_from_delphi`, clickng on the "Exit" html button the main form close, but closing it from system menu, the main form won't close;

How I can detect this system menu "Close" action from main Form and handle the event properly without messing process tricks?

Any advice or code snippets would be greatly appreciated :)
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to Catch WebUI Window Close Event from System Menu 'Close' Button?

Post by salvadordf »

Try using IWebUIWindow.BindAllEvents and then check aEvent.EventType to see if it has the WEBUI_EVENT_DISCONNECTED value.
https://github.com/salvadordf/WebUI4Delphi/blob/348183ef5258caace9d248970ce4c060202f45ed/demos/Delphi_VCL/public_network_access/uMainForm.pas#L72

If that doesn't work try using the Window.beforeunload event in JavaScript to call the same function as the "Exit" button.
flydev
Posts: 6
Joined: Thu Oct 06, 2022 6:02 pm

Re: How to Catch WebUI Window Close Event from System Menu 'Close' Button?

Post by flydev »

Thanks for the suggestions but I can't get it.
I log all events, I've set some others html events as well and nothing happen. The only event catched is the WEBUI_EVENT_DISCONNECTED but I think it's reliable as if you use a second window then the event is sent when closing this window, maybe I have to go deeper checking if there is some handle id attached that I could filter for not closing the app if the event isn't triggered from the main webui window.

I will post an issue on the offical repo and will report here.
Post Reply