Skip to content Skip to sidebar Skip to footer

Trying To Send Data From One Electron Window To Another Via Ipc

Building my first electron app and I'd like the workflow to be as follows: mainWindow opens -> user clicks 'open' button -> 2nd window opens -> user enters input/hits sub

Solution 1:

Your call order is not right when sending input back to renderer.js. You call

win.webContents.send('input-received', data)

when index.html is not yet re-loaded into win!

To fix this you should swap the calls and make sure that the content is ready when you send ipc message

ipcMain.on('input-broadcast', (evt, data) => {
    console.log('input-broadcast happened in main')
    win.loadURL(url.format({
        pathname: path.join(__dirname, 'index.html'),
        protocol: 'file:',
        slashes: true
    }))
    win.webContents.once('dom-ready', () => {
        win.webContents.send('input-received', data)
    })
})

Post a Comment for "Trying To Send Data From One Electron Window To Another Via Ipc"