ipcMain.on("download", (event, info) => {
info.properties.onProgress = status => win.webContents.send("downloadProgress", status);
});
contextBridge.exposeInMainWorld('electron', {
api: {
responseProgress: (channel, func) => {
let validChannels = ["downloadProgress"];
if (validChannels.includes(channel)) {
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
});
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>
)
}