0

This seems like it should be simple. I have a line in main.js that reads:

event.sender.send("name-prompt")

I know that this is being called, I got a warning when I tried to pass in event. Then in index.js I have

ipcRenderer.on("name-prompt", () => {
    console.log("why isn't this working")
    document.getElementById("details-prompt").classList.add("visibility-override")
})

And this just never runs. webContents.send and ipcRenderer.on Not Working uses webContents.send, which as I understand it is distinct from event.sender.send. I'm definitely very new to electron, so there's a lot I'm missing. What should I do to make this work?

Edit: full code for IPCMain.on

ipcMain.on("add-from-file-clicked", (event) => {
    dialog.showOpenDialog({ properties: ['openFile'] }).then(result => {
        console.log(result.canceled);
        console.log(result.filePaths);

        if (!result.canceled) {
            event.sender.send("name-prompt")
        }
    })
})

And yes, I've verified that result.canceled is false. Thanks!

2 Answers2

0

You might want to confirm that you are sending a message from index.js so that main.js can respond with event.sender.send().

There is an example using event.sender.send() in the main.js in the first two code blocks at http://www.atom.pe/docs/api/ipc-main/.
Maybe you could check your code against it.

yixqiao
  • 1
  • 1
  • 2
  • Thank you, I am sending a message from index.js. I had no problems with that. That link is actually where I learned about event.sender.send. –  May 05 '20 at 03:41
0
ipcMain.on("add-from-file-clicked", (event) => {
    dialog.showOpenDialog({ properties: ['openFile'] }).then(result => {
        console.log(result.canceled);
        console.log(result.filePaths);

        if (!result.canceled) {
            event.reply("name-prompt")
        }
    })
})
tpikachu
  • 4,478
  • 2
  • 17
  • 42