firesale-tutorial
firesale-tutorial copied to clipboard
Sending Content to the Renderer Process
In the step where we replace the console.log in openFile function of the main process with the following:
mainWindow.webContents.send('file-opened', file, content);
Then writing renderer code
The md file I picked to display in the console was not sent to the renderer process until I decide to put the line above inside this
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('file-opened', file, content);
});
according to webContents API documentation
did-finish-load is emitted when the navigation is done.
Thanks - I was having the same problem of the "file-opened" event not arriving in the renderer script, and this was the problem. (I'm on Linux, so this might be an OS-specific timing issue?)
I put your solution inside the app.on('ready')
handler, just after the loadURL() call, like this:
mainWindow.loadURL('file://' + __dirname + "/index.html"); //_dirname is directory main.js is in.
mainWindow.webContents.on('did-finish-load', ()=>{
mainWindow.webContents.openDevTools();
openFile(); //TEMP
});
which one to follow?