12345678910111213141516171819 |
- // preload.js
- // 所有的 Node.js API接口 都可以在 preload 进程中被调用.
- // 它拥有与Chrome扩展一样的沙盒。
- const {contextBridge, ipcRenderer} = require('electron')
- window.addEventListener('DOMContentLoaded', () => {
- const replaceText = (selector, text) => {
- const element = document.getElementById(selector)
- if (element) element.innerText = text
- }
- for (const dependency of ['chrome', 'node', 'electron']) {
- replaceText(`${dependency}-version`, process.versions[dependency])
- }
- })
- contextBridge.exposeInMainWorld('electronAPI', {
- setTitle: (title) => ipcRenderer.send('set-title', title)
- })
|