Does anyone have a clean solution for handling closing an app from the os tray?

I would like to be able to close the whole app when a particular window closes via the os tray but not when it closes in general. Is there an event that fires when you close a window from the os tray? I can’t seem to find one.

To handle statechanges like that, you can listen to the event onStateChanged and see if the state is closed:

And here you can see the available states: (edited)

That’s what I’m doing. I have several background windows that the user has no control over, and when they close the main window (and the game is not running) I close everything.

The question was more specific, to handle if it’s closed using the taskbar/systray, not whenever it closes

@Colorfulstan You are right. I need to clarify it:
The event is fired when a window is closed, but as far as I know, there is no way to detect if the window is closed from the tray or the “close” button …

So just to clarify in the future if someone else has this issue. The answer is that there is currently no event fired specifically when closing a window from the os tray. I have a window that I want to be able to close with out closing the app. But if that window closes from the os tray then I do want to close the app.

My current solution is:
When that window closes wait 3-5 seconds and check some condition for whether or not the whole app should close too.

The user likely won’t ever notice that the app is still open for those few seconds if only hidden background window is open. If you have a better/cleaner solution feel free to comment below!

Thank you for sharing you solution.