Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron.js ipc.sendSync Frezees

Hi I'm requesting two results from the main process but when I click the button, the app keeps freezing. Even devtools is not working .

Main.js

ipcMain.on('fmail', (event, arg) => {
  var fmaile = even
  var fmaila = arg  

  ipcMain.on('fpass', (event, arg) => { 
    var fpasse = event
    var fpassa = arg

    console.log(fpassa)
    console.log(fmaila)

    fmaile.returnValue = "info"
    fpasse.returnValue = "info"
  })
})

Javascript

var datamail = ipcRenderer.sendSync('fmail', "fmail");
var datapass = ipcRenderer.sendSync('fpass', "fpass");
console.log(datamail)
console.log(datapass)

Thanks for help.

like image 533
Ahmetcan Aksu Avatar asked Mar 05 '23 19:03

Ahmetcan Aksu


1 Answers

The docs is pretty clear on this one:

Sending a synchronous message will block the whole renderer process, unless you know what you are doing you should never use it.

Since you don't provide a return value in your fmail callback, no wonder it blocks your app.

Also, I guess you wanted to register both listeners individually. What you currently have is "add listener to 'fpass' every time 'fmail' is called back"

Your code should probably look like this (but cannot tell exactly really)

ipcMain.on('fmail', (event, arg) => {
  console.log(arg)
  event.returnValue = "info"
})
ipcMain.on('fpass', (event, arg) => {
  console.log(arg)
  event.returnValue = "info"
})
console.log(
  ipcRenderer.sendSync('fmail', "fmail"),
  ipcRenderer.sendSync('fpass', "fpass")
)
like image 51
pergy Avatar answered Mar 16 '23 14:03

pergy