You should wrap your call in a "on" event on the window.
safeExit = false;
win.on('close', function () {
// show warning if you want
this.close(safeExit);
});
Warning - the above code will go into an infinite loop, you can simply open the console and set safeExit to true to exit the program. I hope this helps!