Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting progress to renderer process... #60

Closed
BardiaKh opened this issue May 24, 2018 · 2 comments
Closed

Getting progress to renderer process... #60

BardiaKh opened this issue May 24, 2018 · 2 comments

Comments

@BardiaKh
Copy link

Hi,

Thanks for the awesome package. I was wondering how can I show the progress in the renderer process. I could not find the right syntax to send it via ipcMain. I would appreciate your help.

Regards,
Bardia

@sindresorhus
Copy link
Owner

Support questions are better asked on Stack Overflow.

@joshuapinter
Copy link
Contributor

Here's a quick snippet that should get you started:

Main

// Handle file downloads on the main thread. Events are emitted from the mainwindow renderer and then handled here.
// Download progress is then passed back as a "downloadProgress" event to the mainWindow renderer.
//
ipcMain.on( "download", async ( event, url, { directory = tempPath } = {} ) => {
  download( mainWindow, url, {
    directory:  directory,
    onProgress: progress => mainWindow.webContents.send( "downloadProgress", progress )
  } );
} );

Renderer

ipcRenderer.on( "downloadProgress", this._downloadProgress.bind( this ) );

ipcRenderer.send( "download", URL );

_downloadProgress( event, progress ) {
  this.setState( { downloadProgress: progress } );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants