sindresorhus / electron-better-ipc

Simplified IPC communication for Electron apps
MIT License
715 stars 60 forks source link

Issues with receiving data from callMain #14

Closed phouse512 closed 5 years ago

phouse512 commented 5 years ago

Issuehunt badges

Hello, I've run into this issue over the past week that I've been unable to move beyond, and I would appreciate another pair of eyes.

In my renderer, I have 2 separate pieces of code that use callMain to get a response back from the main process. One of them returns data just fine, the other returns nothing at all, despite logging showing that the main listener receives it and returns successfully. I even used devtron to see that a message is getting sent to the renderer, but for some reason the listener is not working as expected.

I wonder if I am just fundamentally misinterpreting the library, or if there is something causing my second call to fail. Any thoughts would be appreciated. Main and rendering code is shown below:

renderer.js

// this function works fine
function* checkExistingUser() {
  console.log('checking existing user.');
  const resp = yield ipc.callMain('check-existing-user', 'TESTUSER');
  if (resp.error) {
    console.error('Received error from ipc main');
    return;
  }
  // other behavior
}

// this function doesn't return data from callMain
function* unlockUserCredentials(action) {
  let localUserData = yield select(getLocalData);
  // code makes it here, logging shows up
  try {
    const resp = yield ipc.callMain('unlock-user-credentials', credData);
    console.log(resp); // never shows up in logs
  } catch (error) {
    console.log(error); // never shows up in logs
  }
}

My main file:

// this function responds fine, and data is accessible on the client
ipc.answerRenderer('check-existing-user', async data => {
  // working returns
  return {};
});

// this function returns successfully, even with try catch
ipc.answerRenderer('unlock-user-credentials', async data => {
  return {
    message: 'sample data',
  };
});

am I doing something wrong by having multiple ipc answer renderers here? Any thoughts or ideas are appreciated. As a note, my renderer code is written for use with redux-saga.


IssueHunt Summary #### [garrylachman garrylachman](https://issuehunt.io/u/garrylachman) has been rewarded. ### Backers (Total: $60.00) - [issuehunt issuehunt](https://issuehunt.io/u/issuehunt) ($60.00) ### Submitted pull Requests - [#16 Bugfix #14](https://issuehunt.io/r/sindresorhus/electron-better-ipc/pull/16) --- ### Tips - Checkout the [Issuehunt explorer](https://issuehunt.io/r/sindresorhus/electron-better-ipc/) to discover more funded issues. - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds. --- IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
WhiteMinds commented 5 years ago

I had a similar problem. You can try the downgraded version to solve this problem.

phouse512 commented 5 years ago

@WhiteMinds which version did you downgrade to? thanks for the help!

WhiteMinds commented 5 years ago

@WhiteMinds你把哪个版本降级为?谢谢您的帮助!

"electron-better-ipc": "^0.2.0"

issuehunt-oss[bot] commented 5 years ago

@issuehunt has funded $60.00 to this issue.


particle4dev commented 5 years ago

Reported I had a similar problem. My package version is 0.3.0

phouse512 commented 5 years ago

@particle4dev if you use 0.2.0, does it solve your problem?

particle4dev commented 5 years ago

@phouse512 yes, I downgrade to 0.2.0 and it solves my problem. You can try!

garrylachman commented 5 years ago

I fix the issue in my fork. https://github.com/garrylachman/electron-better-ipc

issuehunt-oss[bot] commented 5 years ago

@sindresorhus has rewarded $54.00 to @garrylachman. See it on IssueHunt

burningTyger commented 5 years ago

The issue seems to be still active. I have to use the fork to receive messages in Main.