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