forked from Annbingbing/Merge-bot-Gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.cjs
More file actions
26 lines (24 loc) · 777 Bytes
/
preload.cjs
File metadata and controls
26 lines (24 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const { contextBridge, ipcRenderer } = require('electron');
// 暴露安全的API给渲染进程
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
send: (channel, data) => {
ipcRenderer.send(channel, data);
},
on: (channel, callback) => {
// 添加事件监听
const listener = (event, ...args) => callback(...args);
ipcRenderer.on(channel, listener);
// 返回取消监听的函数
return () => {
ipcRenderer.removeListener(channel, listener);
};
},
once: (channel, callback) => {
ipcRenderer.once(channel, (event, ...args) => callback(...args));
},
removeAllListeners: (channel) => {
ipcRenderer.removeAllListeners(channel);
}
}
});