Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui.run() doesn't return on macOS when pressing Cmd+Q and using winit #4482

Open
abique opened this issue Jan 30, 2024 · 6 comments
Open

ui.run() doesn't return on macOS when pressing Cmd+Q and using winit #4482

abique opened this issue Jan 30, 2024 · 6 comments
Labels
a:platform-macos Issues specific to macOS (mS,bF) api Changes or additions to APIs bug Something isn't working

Comments

@abique
Copy link

abique commented Jan 30, 2024

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

@tronical tronical added bug Something isn't working a:platform-macos Issues specific to macOS (mS,bF) a:backend-winit Winit backend (mS,mO) labels Jan 30, 2024
@tronical
Copy link
Member

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.

@tronical
Copy link
Member

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.

@tronical tronical added api Changes or additions to APIs and removed a:backend-winit Winit backend (mS,mO) labels Jan 31, 2024
@tronical
Copy link
Member

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().

@tronical
Copy link
Member

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.

@abique
Copy link
Author

abique commented Feb 7, 2024

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.

@tronical
Copy link
Member

tronical commented Aug 29, 2024

I've thought about this again and despite my comment I'm starting to think that perhaps the out of the box experience should result in the event loop terminating gracefully (so that destructors are called). We can implement that in Slint (let's use this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:platform-macos Issues specific to macOS (mS,bF) api Changes or additions to APIs bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants