title: How to send a message from main to render when the electron app closes
body: <p>I have been trying to send a message from the main to the render when the app closes using webcontents but it doesn't seem to have an event where it checks if the app closed.</p>
  
  <p>On the main</p>
  
  <pre><code>mainWindow.webContents.on('did-stop-loading', () =&gt; {
          mainWindow.webContents.send('ping', 'save!')
  });
  </code></pre>
  
  <p>On the renderer</p>
  
  <pre><code>require('electron').ipcRenderer.on('ping', (event, message) =&gt; {
      console.log(message) // Prints 'save!'
  
      // Save json to a file.
      fs.writeFile("library.json", 'json', function(err) {
          if(err) {
              return console.log(err);
          }
          console.log("Library Saved!");
      });
  });
  </code></pre>
  
  <p>This works but I want a way where this is run when the app closes. But webcontents doesn't seem to have a 'close' event like the window does:</p>
  
  <pre><code>mainWindow.on('close', () =&gt; {
          console.log("Run right before the app is closed");
  });
  </code></pre>