-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.ts
43 lines (41 loc) · 1.17 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { contextBridge, ipcRenderer } from 'electron';
const validChannels = ['Updater', 'open-file', 'handle-electron-version'];
contextBridge.exposeInMainWorld('medirefDesktopAPI', {
receive(channel: string, func: (...args: any[]) => void) {
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
const subscription = (_event: Electron.IpcRendererEvent, ...args: any[]) => func(...args);
ipcRenderer.on(channel, subscription);
return () => {
ipcRenderer.removeListener(channel, subscription);
};
}
},
ping() {
ipcRenderer.send('ping');
},
fileHandled() {
ipcRenderer.send('file-handled');
},
viewPdf(url: string, filename: string) {
ipcRenderer.send('view-pdf', url, filename);
},
handleAppMounted() {
ipcRenderer.send('app-mounted');
},
downloadFile(fileData: { url: string; downloadLocationPreference: string; fullName: string }) {
ipcRenderer.send('download-file', fileData);
},
loadUrl(url: string) {
ipcRenderer.send('load-url', url);
},
loadDev() {
ipcRenderer.send('load-dev');
},
loadStaging() {
ipcRenderer.send('load-staging');
},
clearTemp() {
ipcRenderer.send('clear-temp');
},
});