Answers for "update reactjs from electronjs"

0

update reactjs from electronjs

//main.js
ipcMain.on("download", (event, info) => {
info.properties.onProgress = status => win.webContents.send("downloadProgress", status);
  });

//preload.js
contextBridge.exposeInMainWorld('electron', {
  api: {
    responseProgress: (channel, func) => {
        let validChannels = ["downloadProgress"];
        if (validChannels.includes(channel)) { 
        	ipcRenderer.on(channel, (event, ...args) => func(...args));
        }
    },
});
  
//ReactComponent.js
  function ReactComponent() {
  useEffect(() => {
        window.electron.api.responseProgress("downloadProgress", (progress) => {
        console.log(progress);
        console.log(progress.percent);
        });
          }, []);
  return (
    <button onClick={() => {
    //example of calling api on button click
      window.electron.api.process("toMain");
    }}>Download</button>
    )
}
Posted by: Guest on July-21-2021

Code answers related to "update reactjs from electronjs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language