Here's a reference on how to do it with JavaScript:
https://github.com/nwjs/nw.js/wiki/window
My next question that I'll have investigate later is if you can access nw.js with JavaScript with the browser plugin.
If that's possible we can execute a few lines of js at the start of the game that will call a c2 function when the window closes.
Edit:
I'll assume for a moment that you can access nw.js with the browser object.
You'll need the function and browser objects, then execute this js at the start of the layout:
"var gui = require('nw.gui');
var win = gui.Window.get();
win.on('close', function() {
c2_callFunction('nw.js close',[]);
});"
Then add this event anywhere. I should be called before the window is closed.
On function "nw.js close"
--- do something
If the js causes an error so it doesn't work I'll have to look into it further when I get a chance.