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

Nannou application exits immediately on cmd-Q without invoking custom exit handlers #932

Open
jukkae opened this issue Aug 7, 2023 · 0 comments

Comments

@jukkae
Copy link

jukkae commented Aug 7, 2023

Issue Description
When using nannou for developing applications on macOS, I've observed that pressing cmd-Q causes the application to exit immediately. It appears that the window close request event might be handled before nannou's own event loop gets the chance, thus bypassing any custom exit handlers I've set up.

Steps to Reproduce:

  1. Set up a basic nannou application.
  2. Implement a custom exit handler by implementing Drop for Model.
  3. Run the application on macOS.
  4. Sanity check: press esc to verify that the exit handler does run when exiting with esc.
  5. Press cmd-Q to quit the application. The exit handler does not run in this situation.

Here’s a minimal example:

use nannou::prelude::*;

fn main() {
    nannou::app(model)
        .update(update)
        .simple_window(view)
        .run();
}

struct Model {}

impl Drop for Model {
    fn drop(&mut self) {
        println!("saving some important state!");
    }
}

fn model(_app: &App) -> Model {
    Model {}
}

fn update(_app: &App, _model: &mut Model, _update: Update) {
}

fn view(_app: &App, _model: &Model, frame: Frame){
    frame.clear(PURPLE);
}

Expected Behavior: The application should run the custom exit handler before closing, printing “saving some important state!” to console.
Actual Behavior: The application exits immediately without running the custom exit handler.

Potential Impact:
For applications that need to perform critical cleanup tasks or save state before exiting, this behavior could lead to data loss or other unintended side effects. I’d like to use nannou to build a kind of an editor application that auto-saves the project on exit, but not being able to override cmd-Q behavior is a major problem for my usecase.

Suggested Solution:
It would be beneficial if nannou could expose or forward the window close request event to the application before actually closing it, allowing developers to decide how to handle this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant