远程模块 RMI
remote
模块允许从渲染器进程对主进程对象进行简单的 RMI(远程方法调用)。首先在 index.js
中创建主要流程
const {app, BrowserWindow} = require('electron')
let win = null
app.on('ready', () => {
win = new BrowserWindow()
win.loadURL(`file://${__dirname}/index.html`)
win.on('closed', () => {
win = null
})
})
然后远程处理 index.html
<!DOCTYPE html>
<html>
<head>
<script>
const {BrowserWindow, app} = require('electron').remote
</script>
</head>
<body>
<button onclick= "let win = new BrowserWindow(); win.loadURL(`file://${__dirname}/index.html`)">new window</button>
<button onclick= "app.quit()">quit</button>
</body>
</html>