Ok so if I understand correctly you've modified the NW plugin to have a "close app" action. But to me there should be a way for the basic behind-the-scenes runtime scripts to automatically incorporate that action when the window's X is clicked.
I don't really know Javascript at all but I think it should be something sorta like this:
var win = nw.Window.get();
"var gui = require('nw.gui');
nw.Window.get().on('close', function() {
gui.App.quit();
}