html是在renderer进程。如果要调用主进程需要用remote
<input type="button" value="cache" onclick="getCache()"> <script> const { remote, ipcRenderer, shell } = require(‘electron‘); const win = remote.getCurrentWindow(); var getCache=()=>{ var size = win.webContents.session.getCacheSize(); }
const mainProcess = remote.require(‘./main.js‘); </script>
electron In action 示例很好:
https://github.com/electron-in-action