-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpreload.ts
25 lines (24 loc) · 919 Bytes
/
preload.ts
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
import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
myPing() {
ipcRenderer.send('ipc-example', 'ping');
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
on(channel: string, func: (...args: any[]) => void) {
const validChannels = ['ipc-example'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (_event, ...args) => func(...args));
}
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
once(channel: string, func: (...args: any[]) => void) {
const validChannels = ['ipc-example'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.once(channel, (_event, ...args) => func(...args));
}
},
},
});