slint
slint copied to clipboard
`ui.run()` doesn't return on macOS when pressing Cmd+Q and using winit
ui.run() doesn't return on macOS when pressing Cmd+Q and using winit.
Is this a bug? I believe that Cmd+Q is a common way to quit an application and should just make ui.run() return. I have cleanup logic that needs to run after ui.run().
Thanks, Alex
Yes indeed, this seems to be the case. winit calls terminate, which has this bit in its documentation:
Don’t bother to put final cleanup code in your app’s main() function—it will never be executed.
I'm not sure there's that much that we can do, but one thing we should do is invoke the close request on the window. I'll check if that happens, then you can catch that at least.
Ah, we can't catch that, it's not a request after all. winit sends LoopExiting and Destroyed per window, but we don't have hooks for that.
For Android this was solved using dedicated API (#3430), but we may want to have a cross-platform solution in the long run that eliminates the need for main().
The best workaround I can think of right now would be to offer API to invoke a callback when the event loop is about to quit. This doesn't really fit well into the current (global) API, but it would be a natural fit for #4294.
I gave some more thought to this issue and it is extremely important to have a graceful termination path.
I'm thinking to have an embedded database within my application and it would be super problematic if the database can't shutdown nicely and ends up in a corrupted state because of a Cmd + Q.
Worst case scenario I could run it in a child process, but I hope I don't have to.