m4heshd / vuelectro

Bare minimum, simplistic, production ready scaffolding/build tool for developing with :electron: Electron and Vue.Js
MIT License
19 stars 0 forks source link

ipcMain connection between main and renderer #6

Closed hariaakash closed 2 years ago

hariaakash commented 3 years ago

Hi, thanks for this amazing project. I'm new to this electron framework, after jumping around multiple docs and packages this one really did help me get started. Am facing this error only on build apps, any help/guidance is appreciated. When serving locally the app works fine whereas when building the ipcMain handler is not registered.

Here is code: IPC File:

// src/ipc.js

ipcMain.handle('checkForSettingsFile', async () => {
  // Do some processing and return data
  return data;
});

How I am importing it in electron-main.js require(path.resolve('./src/ipc'))

How I am using this in vue:

const checkForSettingsFile = await ipcRenderer.invoke('checkForSettingsFile');

But when running this on production build the following error is thrown:

Error invoking remote method 'checkForSettingsFile': No handler registered for 'checkForSettingsFile'
    at EventEmitter.i.invoke (node:electron/js2c/renderer_init:65)

Edit: Repo https://github.com/hariaakash/tabeazy-connector

m4heshd commented 3 years ago

Hi @hariaakash,

Try opening up vuelectro.config.js and adding ipc/index.js to vMain source files. Like this.

// Configuration for the main process
vMain: {
    srcFiles: [
        'electron-main.js',
        'preload.js',
        'ipc/index.js'
    ]
hariaakash commented 3 years ago

Tried that and the build still showed that same error

m4heshd commented 3 years ago

Just took a look at your source code. Here's what it should be.

vuelectro.config.js :

// Configuration for the main process
vMain: {
    srcFiles: [
        'electron-main.js',
        'preload.js',
        'ipc/index.js',
        'helpers/axios.js',
        'helpers/cron.js',
        'helpers/store.js'
    ]

Also get rid of the path.resolve() in your require() statement.

electron-main.js :

require('./ipc');

Just make sure to add any source file that will potentially be used in the main process to srcFiles in vMain vuelectro configuration. 🙂

BTW, you gave me an idea though. I should add glob support for srcFiles possibly in the next release. Then you could simply add helpers/*.js and it would work.

hariaakash commented 3 years ago

Thanks @m4heshd and yea the global support would be very handy as I have more files to handle

m4heshd commented 3 years ago

I'm gonna keep this open for the moment so the enhancement idea is not lost in closed issues.

m4heshd commented 2 years ago

Glob support has been added in f086a45aad766b6b344dc8d898f1ebe6b23160ea.