Search code examples
macoswebkitnode-webkit

Close window but not app on click of "x" on Mac OS with node webkit


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. enter image description here


Solution

  • The window passes an argument to the callback function if "quit" was clicked, either from the menu bar, or the dock (also on command+Q). I'm 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();
    });