Usually on mac, when I close the window it doesn't quit the app but when using node webkit it does quit the app.
Does anyone know a workaround so when I click the "x" it just closes the window but not the app?
Thanks in advance for your help.
This works for me in MAC:
var gui = require('nw.gui');
var window = gui.Window.get();
gui.App.on('reopen', function(){
window.show();
})
window.on('close', function(){
window.hide();
});
On using above code, If user clicks on close button, it hides window instead of terminating application.
When user clicks on app icon from Dock, GUI reopen
event is triggered which will show hidden window.
Note: reopen is a MAC specific feature currently.
More details provided in NodeWebkit App Features
Not a complete solution, all credits goes to Abhishek's answer.
I've improved it to allow user to close the app and not just quit 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 click the red button, the window gets closed but still runs in the dock, then, right clicking the icon and clicking quit the app is completely closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With