-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
31 lines (29 loc) · 1.19 KB
/
preload.js
File metadata and controls
31 lines (29 loc) · 1.19 KB
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
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("electronAPI", {
windowControl: (action) => ipcRenderer.send("window-control", action),
startVoiceRecognition: () => ipcRenderer.invoke("start-voice-recognition"),
executeCommand: (command) => ipcRenderer.invoke("execute-command", command),
onCommandOutput: (callback) => {
ipcRenderer.on("command-output", (event, data) => callback(data));
},
removeCommandOutputListener: (callback) => {
ipcRenderer.removeListener("command-output", callback);
},
onCommandComplete: (callback) => {
ipcRenderer.on("command-complete", (event, data) => callback(data));
},
removeCommandCompleteListener: (callback) => {
ipcRenderer.removeListener("command-complete", callback);
},
getCwd: () => ipcRenderer.invoke("get-cwd"),
changeDirectory: (directory) =>
ipcRenderer.invoke("change-directory", directory),
getDirectoryContents: (dirPath) =>
ipcRenderer.invoke("get-directory-contents", dirPath),
});
contextBridge.exposeInMainWorld("pathAPI", {
resolve: (...args) => path.resolve(...args),
dirname: (p) => path.dirname(p),
basename: (p) => path.basename(p),
sep: path.sep,
});