daltonmenezes / interprocess

💬 A scalable and type-safe Electron IPC management tool with enhanced DX
https://interprocess.daltonmenezes.com
MIT License
95 stars 2 forks source link

Top-level imports are causing problems in renderer #18

Closed seahindeniz closed 1 year ago

seahindeniz commented 1 year ago

Hello, I'm not sure if interprocess supports any other way to set handlers but following the suggested usage in https://github.com/daltonmenezes/interprocess#-usage section, and importing a dependency to use it in a handler that depends on fsevents.node creates a problem. image

Is there a way to separate the shared ipcs file into each scope so that imported modules won't get interfere with renderer/main scopes?

daltonmenezes commented 1 year ago

Hi @seahindeniz , you can try declaring dependencies like that as external, for example, in electron-vite you can do this!

Also, you can handle the handler as callback on main process, so you avoid imports that can't be joined on both process:

ipcMain.handle.getPing(async (_, { getPing, data }) => {
  // call the registered handler if needed
  const response = await getPing(_, data)

  await ipcMain.invoke.getPong(mainWindow, 'pong')

  ipcMain.remove.getPing()

  return 'The getPong ipc was removed'
})
seahindeniz commented 1 year ago

I'll try your suggestion. If it doesn't work out, I'll try to create a repro case

daltonmenezes commented 1 year ago

@seahindeniz any news?