it always returns undefined, any idea please? i need the return inside fs.reddir but relative to ipcMain
//main
ipcMain.handle('pegaDirRomSalvo', async (event, argx=0) => {
fs.readFile('dataCR.txt', 'utf8', function (err,data) {
if (err) {return '0'}
fs.readdir(data, (err, files) => {
if (err) {throw err;}
return [data,files] //<-------- not going
})
})
})
//render
ipcRenderer.invoke('pegaDirRomSalvo',a=0).then((result)=>{
document.getElementById('divCaminho').innerText = result[0]
})
You need to use
event.sender.sendto trigger another call from themainto therendererprocess to return the result, where the last will listen to it usingipcRenderer.on. Here is a sample solution:renderer:
main:
You can do the same for returning the error details if you want.
EDIT: This technique is usually used when sending the
renderercall usingipcRenderer.sendand receiving it on themainprocess usingipcMain.on.