0

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.

Chris
  • 35
  • 6
  • Where in the documentation are you finding the `proceedToApp` event? My search says it doesn't exist. – Nathan Hawks Jan 04 '20 at 06:11
  • "ProceedToApp" is the channel name. Those are user defined – Chris Jan 04 '20 at 17:27
  • 1
    Oh right -- *headdesk* -- is there an onkeydown wrapped around this perhaps? – Nathan Hawks Jan 04 '20 at 20:08
  • How is the `verifySubscriptionResponse` event emitted and when? – Rhayene Jan 05 '20 at 11:13
  • There is no keydown event wrapper, its just sitting on its own. the verifySubscriptionResponse event is emitted from main. render sends a 'verifySubscription' event to main, main checks a few things, then sends the response event back to render with its findings. if it was valid, render handles a few things on its end and then sends the proceedToApp event back to main, which closes the login window and opens the actual app – Chris Jan 05 '20 at 23:16
  • Ah, I see. Could you add the part where the `verifySubscription` event is emitted? You may want to make sure that this event is not fired more often than you expect. – Rhayene Jan 05 '20 at 23:25

0 Answers0