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

How can I exit an app if closed window? #674

Closed
usagi opened this issue Mar 16, 2020 · 11 comments
Closed

How can I exit an app if closed window? #674

usagi opened this issue Mar 16, 2020 · 11 comments

Comments

@usagi
Copy link

usagi commented Mar 16, 2020

Expected behavor:

image

Actual behavor:

image

In the other words, how can I exit the AppLauncher's loop?

  AppLauncher::with_window(window).use_simple_logger().launch(calc_state).expect("launch failed");
@xStrom
Copy link
Member

xStrom commented Mar 16, 2020

This is a known issue tracked in #265. Right now the solution is to Ctrl+C the console app.

@cmyr
Copy link
Member

cmyr commented Mar 16, 2020

indeed, this is a pretty easy fix if someone is interested, but I'm not going to get to it for a while.

@usagi
Copy link
Author

usagi commented Mar 17, 2020

@xStrom Thank you for the guidance on duplication.

@cmyr Okay, I understand your interest. But I and several developers has interested the issue. Thus, I was PRed #681.

@cmyr
Copy link
Member

cmyr commented Mar 17, 2020

@usagi
Copy link
Author

usagi commented Mar 17, 2020

@cmyr Thanks, I'm read around that and implementation of application.rs for each platforms. And try to it:

    fn remove_window(&mut self, window_id: WindowId) {
        self.with_delegate(|del, data, env, ctx| del.window_removed(window_id, data, env, ctx));
        // when closing the last window:
        if let Some(mut win) = self.windows.remove(window_id) {
            if self.windows.windows.is_empty() {
                // on mac we need to keep the menu around
                self.root_menu = win.menu.take();
                //FIXME: on windows we need to shutdown the app here?
                Application::quit(); // <-- fixing for the problem!

It works and solve the problem for Windows. And it also works on GTK/Linux without a troubles. But, the method also effect to OSX and I saw your old comments for OSX:

Yea, thanks for this. It's a slightly tricky one because there are platform-specific expectations; on windows we should kill the application when the main window closes, but on mac we shouldn't.

There's a separate problem on mac where once the last window is closed the menu stops working. :/

#265 (comment)

Unfortunately, I have not OSX environment then I cannot fix the issue use the simple method without darty [cfg(target_of...)].

@giannissc
Copy link
Contributor

It should be noted that the shello example is closing normally when the button is pressed

@cmyr
Copy link
Member

cmyr commented Mar 17, 2020

What I would recommend is just making this #[cfg(target_os = "windows")]. gtk is handling this elsewhere, and mac is not supposed to close when the last window c loses.

@thecodewarrior
Copy link
Contributor

It would be great if it was an option for macOS. While most apps don't close when their last window closes, that doesn't mean none of them do. The ones that stay open are generally multi-window apps, and the ones that close are ones where there is only ever the one window.

If the app has only the single window there's no way to make a new window once you close the main one, so it should just quit the app. I'm not suggesting doing any kind of auto-detection, but having a toggle would be nice.

@cmyr
Copy link
Member

cmyr commented Mar 19, 2020

You as the programmer are free to exit if the last window is closed, but I would generally think of this as an anti-pattern; at the very least I can't think of an example of a 'well behaved' mac app that does this? Maybe things are relaxing as iOS becomes more dominant, I dunno.

@thecodewarrior
Copy link
Contributor

thecodewarrior commented Mar 20, 2020

After a bit of investigation, I've identified a number of built-in mac apps that quit when their last window closes. They're all apps with only a single window: App Store, Notes, Reminders, Contacts, FaceTime, Calculator, and Dictionary

@cmyr
Copy link
Member

cmyr commented Mar 21, 2020

Interesting, I didn't know that. Thanks!

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

5 participants