I am trying to pass a string from render to main using the ipc process. For some reason its a) firing repeatedly, and b) only sending one letter at a time, even though I can definitively see that the whole string is set before sending. What the heck is going on and how do I compress this back to a single call that has the correct string in it?
renderer:
const electron = window.require('electron');
.
.
.
//by now username = "demouser"
electron.ipcRenderer.once('verifySubscriptionResponse', (event, token, errorMessage) => {
console.log('handleLoginAttempt');
console.log('username variable:' + username);
electron.ipcRenderer.send("proceedToApp", username);
}
main:
const { ipcMain } = require('electron');
ipcMain.on("proceedToApp", (event, username) => {
console.log('passed in username:' + username);
global.loggedInUser = username;
console.log('set username:' + global.loggedInUser)
}
in renderer, im getting the simple output
> handleLoginAttempt
> usernameVariable: demouser
but in main, I get this output:
passed in username:d
set username:d
passed in username:de
set username:de
passed in username:dem
set username:dem
passed in username:demo
set username:demo
passed in username:demou
set username:demou
passed in username:demous
set username:demous
EDIT: One clue to the puzzle, username was a state hook variable, I swapped it out with a literal string and it now sends the entire string, but is still sending several times. So half this problem may be that electron doesnt play well with react hooks logic.