I need to access renderer scripts from electron main menu via onclick. I've added the following to the electron main menu:
{
label: 'Checking for Update',
click: function () {
require('./update')
}
}
.........................
{
label: `Preferences...`,
click: function () {
require('./preferences')
}
}
I'm trying to call preferences.js or update.js above. Both scripts working fine when calling directly from index.html, or from app window via onclick, but not from app menu. When clicked in main app menu its just erroring with
Uncaught Exception:
TypeError: Cannot read property 'app' of undefined
at IncomingMessage.res.on (update.js:20:36)
at emitOne (events.js:96:13)
at IncomingMessage.emit (events.js:188:7)
at IncomingMessage.Readable.read (_stream_readable.js:381:10)
at flow (_stream_readable.js:761:34)
at resume_ (_stream_readable.js:743:3)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
update.js:20 looks like the following:
const appname = electron.remote.app.getName()
There is no remote in the main menu process. Remote module belongs only to renderer so this seems to be reasonable error for me.
But I'm not quite sure how to easily fix this and make scripts work once called from app menu.