sindresorhus / electron-better-ipc

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

Calling `ipc.callFocusedRenderer` when no windows are focused #29

Closed kaatt closed 4 years ago

kaatt commented 4 years ago

The following error is thrown when no windows are focused and ipc.callFocusedRenderer is called:

TypeError: Cannot read property 'id' of null
    at [node_modules]/electron-better-ipc/source/main.js:10:98
    at new Promise (<anonymous>)
    at IpcMainImpl.ipc.callRenderer ([node_modules]/electron-better-ipc/source/main.js:9:54)
    at IpcMainImpl.ipc.callFocusedRenderer ([node_modules]/electron-better-ipc/source/main.js:46:44)

Took me a bit of time to debug, should probably help another person googling it. Would be good to handle this and throw a more descriptive error message.

cc #27 @ulken

ulken commented 4 years ago

@kaatt Good catch. I'll have a look.

ulken commented 4 years ago

@sindresorhus Would you like this to be exclusively handled by callFocusedRenderer() or by callRenderer() in general?

In other words: Is the error that no window is focused or that callRenderer() is called without a BrowserWindow?

Handle both cases?

sindresorhus commented 4 years ago

Handle both cases?

👍

ulken commented 4 years ago

Alright, PR #30 up.