Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Missing return statement in invoke method of preload script in Electron template #479

Closed
keyboard2005 opened this issue Mar 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@keyboard2005
Copy link

Issue

I am new to Electron and encountered an issue with the invoke method in the preload.ts file of a quick-start template. When I called the encapsulated invoke method from the renderer process, I didn't receive a response.

Original code:

invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
  const [channel, ...omit] = args
  console.log('invoke', channel, omit);
  ipcRenderer.invoke(channel, ...omit)
}

However, when I added a return statement to the method, it started working as expected:

invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
  const [channel, ...omit] = args
  console.log('invoke', channel, omit);
  return ipcRenderer.invoke(channel, ...omit)
}

Expected Behavior
The invoke method should return a Promise, allowing the renderer process to receive the promised value from the main process.

Actual Behavior
The invoke method does not return anything, which means the renderer process is unable to receive the resolved value from the main process.

Question
Is this an oversight in the template or by design for some reason? If it's an oversight, the return statement should be included to ensure the invoke method works as intended according to the Electron documentation.

@keyboard2005 keyboard2005 added the bug Something isn't working label Mar 28, 2024
@badspider7
Copy link
Contributor

This problem was already resolved yesterday🎃
please update code #478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants