sindresorhus / electron-better-ipc

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

warning: WebContents #1 called ipcRenderer.sendSync() with 'electron-store-get-data' channel without listeners. #43

Open 1c7 opened 2 years ago

1c7 commented 2 years ago

package.json

"electron": "^15.3.1",
"electron-better-ipc": "^2.0.1",

command

npm run electron

package.json

"scripts": {
  "dev": "vue-cli-service serve --silent"
}

image

1c7 commented 2 years ago

Flie 1: index.js

(not the entire file, but the most important part)

const { app } = require('electron')
const { ipcMain: ipc } = require('electron-better-ipc');

ipc.answerRenderer('app.getAppPath', async () => {
  var result = app.getAppPath();
  return result;
});

function createWindow() {
 win = new BrowserWindow({
    width: 820,
    minWidth: 820,
    height: 840,
    minHeight: 420,
    frame: false,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: true,
      contextIsolation: false,
    }
}

app.whenReady().then(() => {
  createWindow();

  app.on('activate', function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
});

preload.js

window.require = require;

File 2: src/binaries.js

const { ipcRenderer: ipc } = window.require('electron-better-ipc');

async function getAppPath() {
  let app_path = await ipc.callMain('app.getAppPath');
  return app_path
}

(and few other function that depend on getAppPath())

1c7 commented 2 years ago

Seem like it didn't work. my app is getting a blank screen

image

1c7 commented 2 years ago

to be fair I am upgrading my Electron.js v10 app to v15.3.1 so there are a lot of issue.(I am removing a ton of remote code) blank screen likely come from other issue

chuac commented 2 years ago

I ran into something similar trying to use electron-store with Electron v16.0.0. Try calling initialize() and enable() to your index.js like this:

import { initialize, enable } from "@electron/remote/main";

initialize();
// ...
const win = new BrowserWindow({ ... });
enable(win.webContents);
Eve-Sama commented 2 years ago

It happens to me.

"electron": "^20.1.3",

But require @electron/remote/main and call initialize(), enable() do not work for me.

Eve-Sama commented 2 years ago

Add below code in main.js

const ElectronStore = require('electron-store');
ElectronStore.initRenderer();

It works for me!

magnumxpm commented 10 months ago

Add below code in main.js

const ElectronStore = require('electron-store');
ElectronStore.initRenderer();

It works for me!

This resolves the issue it seems. I Used it like this:

import Store from "electron-store"
Store.initRenderer()