-
-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathpreload.js
More file actions
16 lines (12 loc) · 848 Bytes
/
Copy pathpreload.js
File metadata and controls
16 lines (12 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// preload.js: preload script to expose APIs to the renderer process in a secure way
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("electronAPI", {
saveFile: (arg) => ipcRenderer.send("save-file-dialog", arg),
onSaveFileReply: (cb) => ipcRenderer.once("save-file-reply", (_e, arg) => cb(arg)),
readFile: () => ipcRenderer.send("choose-files-dialog"),
onReadFileReply: (cb) => ipcRenderer.once("choose-files-reply", (_e, file, err, text) => cb(file, err, text)),
chooseDirectory: () => ipcRenderer.send("choose-directory-dialog"),
onChooseDirectoryReply: (cb) => ipcRenderer.once("choose-directory-reply", (_e, dir) => cb(dir)),
createTempfile: (arg) => ipcRenderer.send("create-tempfile", arg),
onCreateTempfileReply: (cb) => ipcRenderer.once("create-tempfile-reply", (_e, p) => cb(p)),
});