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

[mac] Need a way to differentiate Cmd-Q from closing window(s) [$500 awarded] #430

Closed
Flamefork opened this issue Feb 8, 2013 · 55 comments
Assignees
Labels
Milestone

Comments

@Flamefork
Copy link

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.

The $500 bounty on this issue has been claimed at Bountysource.

@Flamefork
Copy link
Author

Probably just switching from closeAllWindows to quit is not a good approach, cause there would be no way to do any shutdown work.
One possible solution is to trigger some special quit event in addition to closeAllWindows call. Probably the better solution is to implement some general gracefulQuit App method that works similar to window close.

@Flamefork
Copy link
Author

I would work on this, but need some help on approach for this.

@tommoor
Copy link

tommoor commented Apr 24, 2013

Just hit this issue myself, I can make the app hide when clicking on the close button as many OSX apps do, but unfortunately I get the same behaviour when hitting CMD+Q.

Ideally the window 'close' event would pass some sort of parameter with it to signify where the event came from, currently there is no parameter passed into the callback, so this could be done with backwards compatibility.

@zcbenz - noticed you did the work on this area previously - thoughts?

@timoxley
Copy link

timoxley commented Jun 6, 2013

anyone figure this out?

@tommoor
Copy link

tommoor commented Aug 17, 2013

Would still love to see this tackled, seems like a fairly quick win from an outside perspective.

@hugorodrigues
Copy link

+1

@theabraham
Copy link
Contributor

👍

@tommoor
Copy link

tommoor commented Nov 19, 2013

@rogerwang any thoughts on this one? particularly useful in Mac apps as the different close types usually perform slightly different actions. I.e on most apps clicking the red cross minimises to the dock instead of hard quitting.

@tommoor
Copy link

tommoor commented Dec 20, 2013

@rogerwang in most usecases the expected behaviour of clicking on the red menubar button is that the application should minimize. With NW the app completely quits, simply passing some sort of parameter to know which way exit was triggered would (dock, menubar, shortcut) would allow us to handle this correctly.

thoughts?

@rogerwang
Copy link
Member

Will fix this in 0.8.4

@timoxley
Copy link

🎉

@wengqianshan
Copy link

thx!

@hugorodrigues
Copy link

url-1

@petejkim
Copy link

@rogerwang quitting from dock still does not seem to send "quit" event

@hugorodrigues
Copy link

@rogerwang @petejkim yup, dock quit still not triggering :(
Please check #924

@tommoor
Copy link

tommoor commented Jan 6, 2014

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:

  • Menu
  • Dock
  • Window
  • Shortcut

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...

@Flamefork
Copy link
Author

@tommoor +1

@petejkim
Copy link

@rogerwang please reopen this issue.

@rogerwang rogerwang reopened this Jan 15, 2014
@ghost ghost assigned rogerwang Jan 15, 2014
@rogerwang rogerwang modified the milestones: 0.9.2, v0.8.4 Feb 13, 2014
@rogerwang rogerwang modified the milestones: TBD, 0.9.2 Feb 20, 2014
@tommoor
Copy link

tommoor commented Mar 5, 2014

Just another bump, personally feel like this should have more priority as it's basic window management :'(

@adam-lynch
Copy link

👍

1 similar comment
@hugorodrigues
Copy link

+1

@rogerwang rogerwang added this to the 0.9.3 milestone Mar 21, 2014
@timoxley
Copy link

👍 👍

@tommoor
Copy link

tommoor commented Sep 22, 2014

@rogerwang @mrfabbri do you have an outline of the final solution, how should we handle this?

@rogerwang
Copy link
Member

@tommoor yeah. we'll find a way to distinguish the source of the closing as you suggested. Please file another issue for it, perfectly with some API suggestions.

@tommoor
Copy link

tommoor commented Sep 23, 2014

@rogerwang I just don't understand what this fix does, how does it close the issue? Thanks!

@rogerwang
Copy link
Member

@tommoor the subject of the original report is lost, so I thought it was about NW should send an event when user tries to quit from dock.

@rogerwang rogerwang reopened this Sep 23, 2014
@rogerwang
Copy link
Member

@tommoor I'm a little confused by what the issue is really about, because people are suggesting different things. Since you put the bounty on this issue, is your requirement exactly the comments you left on Jan 6? Do you have any suggestions on the API?

@tommoor
Copy link

tommoor commented Sep 23, 2014

Yes, as comments on Jan 6th. It comes down to the fact that on Mac some applications quit entirely when you click on the red button whilst others simply hide (usually communications/media apps like ours).

I'd suggest making this similar to other events in Javascript, perhaps an event passed to the window close callback (good for future proofing). You could use the currentTarget property or a new property to avoid confusion eg 'source':

var win = gui.Window.get();
win.on('close', function(ev) {
  console.log("You tried to close the app from the " + ev.source);

  if (ev.source != "window") {
    win.close(true);
  }
});

@tommoor
Copy link

tommoor commented Oct 2, 2014

@rogerwang is that helpful? Personally wishing this will get fixed before Yosemite public release as we currently have a fake title bar built in CSS to get around this problem 😱

@rogerwang
Copy link
Member

@tommoor when will be the public release? Currently we are focused on our deadline to catch Chrome 38 release with NW11, but I will try to fix this before that.

@tommoor
Copy link

tommoor commented Oct 3, 2014

@rogerwang now in GM (Gold Master) status, next release is public which will be before the end of the month, likely around three weeks.

http://www.macworld.co.uk/news/mac-software/mac-os-x-yosemite-release-date-launching-soon-features-uk-price-3493748/

@mrfabbri
Copy link
Member

mrfabbri commented Oct 8, 2014

Hi @tommoor, 33c1255 fix the quit from dock (and also hitting cmd+q while cmd+tabbing) so that the app does not terminate immediately and windows on close 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:

var gui = require('nw.gui');
var win = gui.Window.get();

win.on('close', function(event) {
  if (event == 'quit') {
    win.close(true);
  } else { 
    // event is `undefined`
    win.hide();
  }
});

gui.App.on('reopen', function() {
  win.show();
});

Right now the close event differentiates (only) between

  • a quit "request" from menu, dock, shortcut (with 'quit' as the event parameter being passed to the close handler) and
  • a close "request" from the window (with no event parameter -i.e. undefined- being passed to the close handler). Maybe a 'window' parameter would provide a clearer distinction from the other case.

By using NSApplication.currentEvent inside applicationShouldTerminate it should be possible to find out the source of the termination request (dock, menu, ...) and pass a proper parameter to nw::App:CloseAllWindows() which should be modified (along with ShouldCloseWindow in Shell and the NativeWindowDelegate) to accept a parameter (enum? int?) other than the bool 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.

@tommoor
Copy link

tommoor commented Oct 8, 2014

@mrfabbri appreciate the clarification. I'll give this a blast on the pre-release as soon as I can 😄

@tommoor
Copy link

tommoor commented Oct 9, 2014

@mrfabbri @rogerwang I can confirm this works for the usecase, we should make sure to document this well 😃

Lets close this bad boy!

@ghostoy
Copy link
Member

ghostoy commented Nov 7, 2014

@rogerwang Will there be a 0.10.6 release later?

@tommoor
Copy link

tommoor commented Nov 17, 2014

Hey @mrfabbri could you claim or decline the bounty on this issue? If you don't want it I would like to redistribute the money to some other issues in this repo that need solving 😄

@mrfabbri
Copy link
Member

claimed! 😄

@tommoor
Copy link

tommoor commented Nov 18, 2014

My pleasure ;-) thanks!

On Tue, Nov 18, 2014 at 11:48 AM, Marco Fabbri [email protected]
wrote:

claimed! 😄

Reply to this email directly or view it on GitHub:
#430 (comment)

@tommoor
Copy link

tommoor commented Nov 24, 2014

@rogerwang this can be closed.

@rogerwang rogerwang changed the title [$500] [$500 awarded] Feb 21, 2015
@rogerwang rogerwang changed the title [$500 awarded] [mac] Need a way to differentiate Cmd-Q from closing window(s) [$500 awarded] Feb 21, 2015
@varshneyjayant
Copy link

Thanks guys! this saved my day :)

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

No branches or pull requests