-
Notifications
You must be signed in to change notification settings - Fork 3
/
preload.js
46 lines (41 loc) · 1.91 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// preload.js
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
const { contextBridge, ipcRenderer } = require("electron");
const path = require("path");
const fs = require("fs");
let jqFileContents = fs.readFileSync(
path.join(__dirname, "js", "jquery.min.js"),
{
encoding: "utf8",
}
);
contextBridge.exposeInMainWorld("electronAPI", {
JqueryString: () => jqFileContents,
// --- renderer to main - 1 way
msgBox: (text, caption) => ipcRenderer.send("show-msgbox", text, caption),
relaunchApp: () => ipcRenderer.send("app-relaunch"),
urlIncludesToBlock: (includes) =>
ipcRenderer.send("block-includes", includes),
toggleFullScreen: () => ipcRenderer.send("toggle-fullscreen"),
maximizeApp: () => ipcRenderer.send("maximize-app"),
startCheckCaptcha: () => ipcRenderer.send("start-check-captcha"),
stopCheckCaptcha: () => ipcRenderer.send("stop-check-captcha"),
// --- renderer to main - 2 way
rootDir: () => ipcRenderer.invoke("dir-root"),
createDir: (dirPath) => ipcRenderer.invoke("dir-create", dirPath),
readFile: (filePath) => ipcRenderer.invoke("file-read", filePath),
writeFile: (filePath, contents) =>
ipcRenderer.invoke("file-write", filePath, contents),
downloadFile: (url, filePath, index, cb) =>
ipcRenderer.invoke("file-download", url, filePath, index, cb),
pathExists: (somePath) => ipcRenderer.invoke("path-exists", somePath),
deletePath: (somePath) => ipcRenderer.invoke("path-delete", somePath),
sendInput: (type, accelerator) =>
ipcRenderer.invoke("send-input", type, accelerator),
updateApp: (appZipUrl) => ipcRenderer.invoke("app-update-self", appZipUrl),
// --- main to renderer
log: (callback) => ipcRenderer.on("log-message", callback),
onAppMaximized: (callback) => ipcRenderer.on("on-app-maximized", callback),
onAppUnMaximized: (callback) => ipcRenderer.on("on-app-unmaximized", callback),
});