Page 1 of 1

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

Posted: Wed Nov 27, 2024 9:17 am
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 :)

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

Posted: Wed Nov 27, 2024 2:23 pm
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.

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

Posted: Thu Nov 28, 2024 8:57 am
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.