Adding a callback function from the main.js to the renderer.js after button click in another window (electron))

Hi I’m currently working on an electron app. At the moment i have used the ipcRenderer in one of my JS files (sidebar.js) to execute a function in the main.js. This code executes without a problem. What I’m trying to do straight after is send a callback function to the main renderer.js file so that i can execute another function which manipulates the appearance of some icons in the main window.

sidebar.js code:

const ReadyBtn = document.getElementById('btnReady') 
ReadyBtn.addEventListener('click', function(){


main.js code:

ipcMain.on('ReadyBtn', (event) => { 
console.log('request received')
event.returnValue = "toggle ready test";

The code above works fine, when the button is clicked the toggleReady() function within the main.js file is triggered.

What I would now like to do is set up a call back function in the renderer.js file so that I can execute another function “stateReady()”, after the button is clicked. Below is what i have so far:

(async () =>{
await ipcRenderer.invoke('ReadyBtn')


Any help would be much appreciated!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.