const { ipcRenderer } = require('electron') // 1. 显示版本号逻辑 (保持不变) 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]) } }) // 2. 修正:直接挂载到 window 对象 // 因为你的 main.js 中 contextIsolation: false,所以直接赋值即可 window.sysAPI = { // 读取历史记录 readHistory: () => ipcRenderer.invoke('history:read'), // 写入历史记录 writeHistory: (data) => ipcRenderer.invoke('history:write', data), // 读取任意 JSON 文件 readJsonFile: (filePath) => ipcRenderer.invoke('file:read-json', filePath), //获取软件版本 getAppVersion: () => ipcRenderer.invoke('app:get-version') };