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

Graceful shutdown of native eframe #814

Open
emilk opened this issue Oct 18, 2021 · 5 comments
Open

Graceful shutdown of native eframe #814

emilk opened this issue Oct 18, 2021 · 5 comments
Labels
eframe Relates to epi and eframe feature New feature or request

Comments

@emilk
Copy link
Owner

emilk commented Oct 18, 2021

Sparked by #813

There are two user stories we want to support:

When a user closes the native eframe window (e.g. by clicking the X or pressing Ctrl-F4/Cmd-Q)…

…the egui app should continue and show a "Do you want to save your work" popup (using egui).

…the native window should close immediately, but the app should be able to take its time to save data to disk, etc.

For the first case eframe would need to communicate the closing as an event to the App rather than shutting down directly, and then have the app tell eframe when it is actually time to quit.

For the second case: currently if App::on_exit is slow, the native window will linger, frozen and unresponsive (bad). The fix is probably as simple as moving around some code in egui_glium and egui_glow.

@emilk emilk added feature New feature or request eframe Relates to epi and eframe labels Oct 18, 2021
@follower
Copy link
Contributor

I was wanting this functionality a while ago (to allow time for network connections to close cleanly while still showing UI progress feedback).

I got as far as determining that AFAICT the reason this wasn't currently possible was due to treating WindowEvent::CloseRequested & WindowEvent::Destroyed as being identical here:

WindowEvent::CloseRequested | WindowEvent::Destroyed => true,

I did not get as far as writing this up until now, however. :)

As I understand it, to enable graceful shutdown we'd need to treat WindowEvent::CloseRequested as a separate event type.

@jakeisnt
Copy link

jakeisnt commented Jan 9, 2023

Is this already implemented? This example: https://github.com/emilk/egui/tree/master/examples/confirm_exit seems to work.

@coderedart
Copy link
Contributor

This example: https://github.com/emilk/egui/tree/master/examples/confirm_exit seems to work.

the example shows how to close the application using frame.close(). developer can close the window anytime using that.

this issue is more about intercepting an external close event (clicking red X close button on window's titlebar or system alt+f4 shortcut etc..). then, just forward the close event to the developer. then, dev can decide whether to close the app or show a prompt before calling frame.close or save the state to disk before closing or just ignore it even.

@jakeisnt
Copy link

jakeisnt commented Jan 9, 2023

It intercepts! The on_close_event function defined when implementing the eframe app is invoked when a user attempts to close the window. In this case, the function flips a boolean that shows the exit dialog to the user.

When attempting to close the window of that demo on my (Linux/Wayland) machine, instead of the window closing, I see the dialog.

Try it on yours 😁

@coderedart
Copy link
Contributor

coderedart commented Jan 9, 2023

It intercepts

oh.. you are right. i didn't know about on_close_event until now. I guess this issue is already solved then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants