Hi everyone,
I have an electron app, which I need to implement serial communication, and run the function through ipc from the renderer. Should I implement the functions in main.js, or there is a better solution for it? For example in a 'utils.js' which i require in the main.js.
So the main question is that is recomended or not to handle all the backend/hardware processes in the main.js?
#backend processes not in main.js
16 messages · Page 1 of 1 (latest)
name of the file doesnt matter
I know, i just wrote it for example. It bothers me to create a gigantic main.js file and i don't know if it should or not
you can split your code into multiple files
but since the ipc comm. works between the main and the renderer I still whould have to call the functions from the main.js, right?
ohh, then if the ipcMain would be not in the main.js, where?
anywhere
and how can i link that file to the main ?
with require()
I tried this, but the main->renderer ipc doesn't work, because in the utils.js (which contains tha main->renderer ipc) the mainWindow is not defined .
"mainWindow.webContents.send('data-reply', someData); // Send data back to renderer"
then you should somehow pass that window
thanks, i'm trying to figure it out. At least the renderer->main works
In utils.js create and export a function that takes in some arguments, more specifically the mainWindow. In main.js you can call this function and pass in your mainWindow. Something like that should work