被 claude 生成的代码坑到了···
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
send: (channel, ...args) => {
ipcRenderer.send(channel, ...args);
},
on: (channel, func) => {
ipcRenderer.on(channel, (event, ...args) => func(...args));
},
removeListener: (channel, func) => {
// 这能 remove 才怪···
ipcRenderer.removeListener(channel, func);
}
}
});