forked from microsoft/dicom-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreload.js
30 lines (28 loc) · 1.32 KB
/
preload.js
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
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------
// based on answer from https://stackoverflow.com/questions/57807459/how-to-use-preload-js-properly-in-electron
const {
contextBridge,
ipcRenderer
} = require("electron");
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
"api", {
send: (channel, data) => {
let validChannels = ["postFile", "selectFile", "getChangeFeed"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = ["filePosted", "fileSelected", "httpErrorEncountered", "errorEncountered", "success", "changeFeedRetrieved"];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);