electron-better-ipc
electron-better-ipc copied to clipboard
warning: WebContents #1 called ipcRenderer.sendSync() with 'electron-store-get-data' channel without listeners.
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"
}
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()
)
Seem like it didn't work. my app is getting a blank screen
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
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);
It happens to me.
"electron": "^20.1.3",
But require @electron/remote/main
and call initialize(), enable()
do not work for me.
Add below code in main.js
const ElectronStore = require('electron-store');
ElectronStore.initRenderer();
It works for me!
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()