nw.js: [mac] Need a way to differentiate Cmd-Q from closing window(s) [$500 awarded]
Common pattern for apps is to hide on window close but quit on Menu->Quit
(Cmd-Q).
Currently, Quit menu item calls closeAllWindows
, thus triggering close
event for each window. There seems to be no straight way to distinguish between this two events.
<bountysource-plugin>
The $500 bounty on this issue has been claimed at Bountysource. </bountysource-plugin>
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 55 (13 by maintainers)
Hi @tommoor, 33c12555d6d67f75c393c7f4c9136c5bde13611d fix the quit from dock (and also hitting
cmd+q
whilecmd+tab
bing) so that the app does not terminate immediately and windows onclose
handlers are properly called (with'quit'
as the event parameter) .In the v0.10.6-pre-osx-x64 version @rogerwang posted earlier in the thread you can try something like:
Right now the close event differentiates (only) between
'quit'
as the event parameter being passed to theclose
handler) andundefined
- being passed to theclose
handler). Maybe a'window'
parameter would provide a clearer distinction from the other case.By using
NSApplication.currentEvent
insideapplicationShouldTerminate
it should be possible to find out the source of the termination request (dock, menu, …) and pass a proper parameter tonw::App:CloseAllWindows()
which should be modified (along withShouldCloseWindow
inShell
and theNativeWindowDelegate
) to accept a parameter (enum? int?) other than thebool quit
. What is your opinion @rogerwang on this?That said, I think most of the use cases are having a simple differentiation between the close window versus quit application and the further differentiation for dock, menu should not hinder this simple case, i.e. being able to tell
if (event = 'quit') { ... }
independently from the source of the quit event.I can’t help but wonder if this would be better just having a parameter on the exit event that tells you which of the places its being triggered from:
It’s then upto the developer to choose whether the app should close in those situations? As some apps will want to close with the window and others not…