I got it working! First, whenever I call my function that captures the windows [X] close button, I first release control (to help prevent duplicate "listeners") by removing all listeners from the 'close' signal. You'll note the below code is very similar to previous solutions, but adds an extra line that I guess was a recent requirement to listen for 'close' signals: var gui = require("nw.gui")
Browser -> Execute javascript:
"var gui = require(""nw.gui"");
var win_main=gui.Window.get();
win_main.removeAllListeners('close');"
Then, I run a second command that listens for the 'close' signal.
Browser -> Execute javascript
"var gui = require(""nw.gui"");
var win_main = gui.Window.get();
win.on('close', function() {
c2_callFunction('nw.js close',[]);
});"
I have a Function titled "nw.js close" where I run the code I want to run when the player clicks the window [X] close button.
And then when I want to release control I run just that code at the top of my post, removeAllListeners.
This works in the latest NWJS 0.84.0 on Windows, and I'll be testing my update on Mac and Linux next week.