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.
On the main
mainWindow.webContents.on('did-stop-loading', () => {
mainWindow.webContents.send('ping', 'save!')
});
On the renderer
require('electron').ipcRenderer.on('ping', (event, message) => {
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!");
});
});
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:
mainWindow.on('close', () => {
console.log("Run right before the app is closed");
});