Electron JS event is firing multiple times

后端 未结 2 783
误落风尘
误落风尘 2020-12-22 09:00

In electronJS, I have created a custom application menu in which I\'m sending the event from main process to renderer process, but now what happening is where I\'m listening

相关标签:
2条回答
  • 2020-12-22 09:55

    So after a lot of searching I found the answer.If you are switching the routes and registered some channels on one component and some on other, So you can remove the listeners for the particular channels in a lifecycle method(destroyed) when the component is unmounted. My issue was I was switching between routes and every time created was running in which I registered ipc renderer to listen to those channels. So i removed the listeners to the channels in destroyed lifecycle hook.

    It can be done by:

    ipcrenderer.removeAllListeners([channel])

    Here's is the link for docs: Electron

    0 讨论(0)
  • 2020-12-22 09:57

    ipcRenderer.on continuously listens, while once is only invoked for the next event - then removed.

    ipcRenderer.once(*channel*, *listener*)

    Source: http://man.hubwiz.com/docset/electron.docset/Contents/Resources/Documents/docs/api/ipc-renderer.html

    0 讨论(0)
提交回复
热议问题