加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
preload.js 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
godo 提交于 2023-08-21 03:27 . add pre
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
// Preload (Isolated World)
// 三种方式在main与html之间通信
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld(
'ipcRenderer',
{
// From render to main.
send: (channel, args) => { return ipcRenderer.sendSync(channel, 'ping') },
// From main to render.
// listener为自定义的消息处理函数,原型在renderer中
receive: (channel, listener) => {
ipcRenderer.on(channel, (event, args) => listener(args));
},
// From render to main and back again.
invoke: (channel, args) => {
return ipcRenderer.invoke(channel, args);
}
}
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化