Reputation: 11
I'm newbie. I have some problem!
As a title, help me pls. I got this bug Even if I set enableremotemodule = true. This is my code
javascript:
const $ = require('jquery');
const remote_v = require("electron").remote;
var win = remote.getCurrentWindow();
$('#minimize').click(function(){
remote_v.BrowserWindow.getFocusedWindow().minimize();
});
$('#close').click(function(){
remote_v.getCurrentWindow().close();
});
main.js
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 530,
height: 330,
resizable: false,
frame : false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')
mainWindow.webContents.openDevTools();
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
Thank you very much, have a nice day!.
Upvotes: 0
Views: 4303
Reputation:
// Deprecated in Electron 12:
const { BrowserWindow } = require('electron').remote
Install the @electron/remote
module
// Replace with:
const { BrowserWindow } = require('@electron/remote')
// In the main process:
require('@electron/remote/main').initialize()
Note: In electron >= 14.0.0, you must use the new enable API to enable the remote module for each desired WebContents separately:
require("@electron/remote/main").enable(win.webContents);
Here are the changes in the API. I am sure this helps you figure out the new changes since the remote module is removed from latest electron.
Upvotes: 2
Reputation: 161
New version of electron ( I use 15.0.0) doesn't have remote module any more. If you look at documentation, you'll see that it doesn't have enableRemoteModule option. Maybe this can help you.
// In main process.
const { ipcMain } = require('electron')
ipcMain.on('asynchronous-message', (event, arg) => {
console.log(arg) // prints "ping"
event.reply('asynchronous-reply', 'pong')
})
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg) // prints "ping"
event.returnValue = 'pong'
})
// In renderer process (web page).
// NB. Electron APIs are only accessible from preload, unless contextIsolation is disabled.
// See https://www.electronjs.org/docs/tutorial/process-model#preload-scripts for more details.
const { ipcRenderer } = require('electron')
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg) // prints "pong"
})
ipcRenderer.send('asynchronous-message', 'ping')
Upvotes: 0
Reputation: 1271
According to documentation it's just a syntax problem.
const $ = require('jquery');
const {BrowserWindow} = require("electron").remote;
$('#minimize').click(function(){
BrowserWindow.getFocusedWindow().minimize();
});
$('#close').click(function(){
BrowserWindow.getFocusedWindow().close();
});
Upvotes: 0