Close window but not application when clicking "x" on Mac OS using node webkit

Usually on mac, when I close the window, it does not exit the application, but when using node webkit it leaves the application.

Does anyone know a workaround, so when I press "x" it just closes the window, but not the application?

Thanks in advance for your help. enter image description here

+7
webkit macos node-webkit
source share
4 answers

The window passes the argument to the callback function if you click "quit", either from the menu bar or using the dock (also with the + Q command). I am using this code and it works as expected:

var gui = require('nw.gui'), app = gui.App, win = gui.Window.get(); win.on('close', function (action) { 'quit' === action ? app.quit() : win.hide(); }); app.on('reopen', function(){ win.show(); }); 
+1
source share

This works for me on MAC:

 var gui = require('nw.gui'); var window = gui.Window.get(); gui.App.on('reopen', function(){ window.show(); }) window.on('close', function(){ window.hide(); }); 

When using the above code, if the user clicks the close button, he hides the window instead of terminating the application.
When the user clicks on the application icon from the Dock, the reopen GUI event is reopen , which displays a hidden window.
Note. Re-open the MAC-specific function at this time.
For more information, see NodeWebkit Application Features.

+3
source share

Not a complete solution, all loans go to the answer Abhishek.

I improved it so that the user can close the application, and not just exit the window.

  var hidden = false; gui.App.on('reopen', function(){ hidden = false; win.show(); }) win.on('close', function(){ if (hidden == true) { gui.App.quit(); } else { win.hide(); hidden = true; } }); 

With this trick, the first time you press the red button, the window closes, but it still works in the dock, then by right-clicking the icon and clicking exit , the application is completely closed.

+3
source share

Yes, there is a way. I call it command + Q. Another way you can do this is command + control + power

0
source share

All Articles