title: Cannot access window close function in Desktop Application using node js
body: <p>I am developing a windows desktop application using node.js and backbone.js. 
  I want to perform an action when the user closes the app by clicking on the close button on the title bar or right clicking on the application from windows taskbar.</p>
  
  <p>My app.js looks like this,</p>
  
  <pre><code> var app = module.exports = require('appjs');
  
  
  app.serveFilesFrom(__dirname + '/content/assets/');
  
  var menubar = app.createMenu([ {
  label : '&amp;File',
  submenu : [ {
      label : 'E&amp;xit',
      action : function() {
          window.close();
      }
  },{
      label : 'New',
      action : function() {
          window.test();
      }
  } ]
  }, {
  label : '&amp;Window',
  submenu : [ {
      label : 'Fullscreen',
      action : function(item) {
          window.frame.fullscreen();
          console.log(item.label + " called.");
      }
  }, {
      label : 'Minimize',
      action : function() {
              console.log("df");
          window.frame.minimize();
      }
  }, {
      label : 'Maximize',
      action : function() {
          console.log("nnnnnnlaaaaaaaaaaaaaaa");
          window.frame.maximize();
      }
  }, {
      label : ''// separator
  }, {
      label : 'Restore',
      action : function() {
          window.frame.restore();
      }
  } ]
  } ]);
  
  menubar.on('select', function(item) {
  console.log("menu item " + item.label + " clicked");
  });
  
  var trayMenu = app.createMenu([ {
  label : 'Show',
  action : function() {
      window.frame.show();
  },
  }, {
  label : 'Minimize',
  action : function() {
      window.frame.hide();
  }
  }, {
  label : 'Exit',
  action : function() {
      window.close();
  }
  } ]);
  
  var statusIcon = app.createStatusIcon({
  icon : './data/content/icons/32.png',
  tooltip : 'AppJS Hello World',
  menu : trayMenu
  });
  
  
  
   var window = app.createWindow({
   width : 1024,// 640
  height : 768,
  showChrome: true,
  icons : __dirname + '/content/icons'
  });
  window.on('create', function() {
  console.log("Window Created");
  window.frame.show();
  window.frame.center();
  window.frame.maximize();
  window.frame.setMenuBar(menubar);
  });
  
  window.on('ready', function() {
  console.log("Window Ready");    
  window.require = require;
  window.process = process;
  window.module = module;
  //window.frame.openDevTools();
  window.fileAssoc = process.mainModule.filename;
  //window.readMyFile();
  function F12(e) {
      return e.keyIdentifier === 'F12'
  }
  function Command_Option_J(e) {
      return e.keyCode === 74 &amp;&amp; e.metaKey &amp;&amp; e.altKey
  }
  
  
          });*/
  
  
  window.addEventListener('keydown', function(e) {
  console.log("hi");      
      if (F12(e) || Command_Option_J(e)) {            
          window.frame.openDevTools();
      }
     });
     }); 
  </code></pre>
  
  <p>Please find the attached screenshot. I am able to perform actions on custom added functionalities inside "File" &amp; "Windows". </p>
  
  <p>But i don't know how to capture the event when the default app close button in the title bar is clicked or closed by right clicking on the application from windows task bar. Please help.
  <a href="https://i.stack.imgur.com/Tb2dJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tb2dJ.png" alt="enter image description here"></a></p>
  
  <p>Thanks in Advance</p>