I have some data in the localstorage that has to be deleted on app.quit()
. But I see no way to do so from the main process.
Is there a way to call a renderer
function from main
?
I know about var remote = require('remote');
but it seems to go only in the wrong direction.
You might use BrowserWindow.webContents.executeJavaScript like so in your main process:
Although you might consider it a kinda messy/dirty approach, it works. And it does not require setting up anything in the renderer process which greatly simplified things for me.
If you just want to call a particular method it would probably be quicker to write this way.
You can send messages from the main process to a renderer process via webContents.send as called out in the documentation here: https://github.com/atom/electron/blob/master/docs/api/web-contents.md#webcontentssendchannel-arg1-arg2-.
Here is how you do it straight from the docs:
In the main process:
In index.html:
Note it is asynchronous. I am not sure how that affects things with your particular solution, but this should at least get you talking back to the renderer process.