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

App won't quit on Mac #7355

Closed
aliblackwell opened this issue Feb 5, 2020 · 8 comments
Closed

App won't quit on Mac #7355

aliblackwell opened this issue Feb 5, 2020 · 8 comments

Comments

@aliblackwell
Copy link

NWJS Version : 0.44.0
Operating System : Mac OS Catalina 10.15.1

Expected behavior

Quitting the app from the system menu or by right-clicking the dock icon should quit the app. Processes nwjs, nwjs Helper, nwjs Helper (GPU) and nwjs Helper (Renderer) should all disappear from the Activity Monitor and the tray icon and dock icons should disappear.

Actual behavior

The icon remains in the dock and the tray menu remains. nwjs, nwjs Helper, nwjs Helper (GPU) and nwjs Helper (Renderer) are all still active in Activity Monitor.

Calling the nw.App.quit() method manually does successfully close the app.

Running with --disable-features=nw2 does lead to expected behaviour.

How to reproduce

  • Download the zip nw2_quit_bug.zip, unzip and navigate into nw2_quit_bug using your terminal
  • Run $ npm install to install latest nwjs release: v0.44.0
  • Run $ npm start to start the app. A paw icon will appear in system tray.
  • Try to quit the app using the nwjs System menu or by right-clicking the dock icon and choosing Quit.
@rogerwang
Copy link
Member

Thanks for reporting. But your sample works for me.

@Blatman
Copy link

Blatman commented Feb 6, 2020

FWIW - I tried test app on 10.13.6 (0.44.0) and it will not quit without force-quit. OK with nw2 disabled. I tested by just dropping nwjs into the src folder and double-clicking (probably why the taskbar icon showed the nwjs icon rather than the paws). My apps with windows are OK so maybe this is only an issue if there is no window.

@panther7
Copy link

panther7 commented Feb 6, 2020

I think, that it's similar to #7271.

@arudnev
Copy link

arudnev commented Feb 6, 2020

I'm on macOS Catalina 10.15.3

This works as expected:

./nwjs-sdk-v0.44.0-osx-x64/nwjs.app/Contents/MacOS/nwjs --disable-features=nw2 nw2_quit_bug

This one quits when clicking Quit App in tray menu, but does not quit when clicking Quit after right-click on dock icon

./nwjs-sdk-v0.44.0-osx-x64/nwjs.app/Contents/MacOS/nwjs nw2_quit_bug

We observe the same with other app that has "main": "index.html" and opens a window.
In our app when you click Quit it just hides the window.
If you click on the dock icon after that it re-opens the app ("reopen" even is fired by App).
If you click on Quit after re-open one more time the window does not get hidden.
It does not seem to fire "close" event on the Window when Quit menu item is clicked, but command + Q does exit the app.

@arudnev
Copy link

arudnev commented Feb 7, 2020

I did some more testing, it seems that all comes down to difference in how Quit action on dock icon menu and how close event are handled in nw1 vs nw2 modes.

First of all, if app does not have window then Quit on dock icon menu does not exit the app, if app has window and does not add handler for close event then the app will exit as expected.

Now, if app adds handler to close event it all works differently between nw1 and nw2 modes.

In nw1 mode Quit on dock icon would simply exit the app without firing close event.

In nw2 mode it fires close event, but with quit argument being undefined.

So, if logic for handling of close event relies on quit argument to decide if app should be exited or simply hidden (typical behavior for some app types, i.e. messaging apps) then in nw2 mode it can not distinguish between Quit on dock icon menu vs close button in the window frame.

It can be demonstrated by running something like this in dev console in vanilla sdk install and then attempting Quit via dock icon menu:

nw.Window.get().on('close', (q) => { alert(q ? 'quit' : 'hide'); q && nw.App.quit(); })

Also, not that it matters, in nw2 mode subsequent clicks on Quit in dock icon menu don't fire close event at all and some other listeners seem to be de-registered after first click on Quit as well, i.e. Quit nwjs menu item in top menu that would fire close with quit=undefined in nw2 mode (as opposed to expected quit='quit' as would in nw1 mode) before clicking on Quit would not fire after close event triggered by Quit.

@rogerwang
Copy link
Member

This shares similar root cause with #7298

@rogerwang
Copy link
Member

This is fixed in git and will be available in the next nightly build.

@aliblackwell
Copy link
Author

Thank you both (@rogerwang and @arudnev) so much! This is fantastic news.

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