firesale-tutorial icon indicating copy to clipboard operation
firesale-tutorial copied to clipboard

Sending Content to the Renderer Process

Open ghost opened this issue 8 years ago • 2 comments

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.

ghost avatar Dec 26 '16 00:12 ghost

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
  });

DarrenCook avatar Jan 25 '17 18:01 DarrenCook

which one to follow?

awwwd avatar May 16 '17 19:05 awwwd