I'm trying to make an Electron app with an input, which value will be used for setting the app's progress bar via win.setProgressBar()
I tried to use ipc to send a message from the renderer process to the main process. I tried adding blur and click event listeners for the input, using a function defined above, but they don't seem to be applied correctly.
Renderer process :
const {ipcRenderer} = require("electron");
function setProgress(pgrss) {
console.log("fromage"); // For debugging purposes
ipcRenderer.send("sendMainMessage", {
progress: pgrss
});
};
document.getElementById("progress").addEventListener("click", setProgress(parseFloat(document.getElementById("progress").value)));
Input in HTML page :
<div class="pane">
<input id="progress" type="number" value="0.5">
</div>
Loading the renderer JS in HTML page :
<script>
require("electron-photon")
require('./renderer.js')
</script>
Main process ipc receiver :
const {app, BrowserWindow, ipcMain} = require('electron')
// ...
ipcMain.on("sendMainMessage", (event, properties) => {
mainWindow.setProgressBar(properties.progress);
});
I except the app's progress bar to be set to the value I'm putting in the input field when the event on it happens, via the renderer process and ipc. According to devtools, it looks like the renderer process's function used for the event listener runs once at load, and the event listener isn't applied to the input field. Here's what shows in the console, doesn't depend on if something was typed in the input or not : https://i.stack.imgur.com/3Ca5j.png . And in the Event Listener tab for the input element, no event listener shows from the renderer script.