-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
24 lines (23 loc) · 1.34 KB
/
preload.js
File metadata and controls
24 lines (23 loc) · 1.34 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
const { contextBridge, ipcRenderer } = require('electron');
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
// Methods needed for IPC communication
send: (channel, ...args) => ipcRenderer.send(channel, ...args),
on: (channel, callback) => {
ipcRenderer.on(channel, (_, ...args) => callback(...args));
},
removeAllListeners: (channel) => ipcRenderer.removeAllListeners(channel),
// Invoke methods
openDirectoryDialog: () => ipcRenderer.invoke('open-directory-dialog'),
readDirectory: (directoryPath) => ipcRenderer.invoke('read-directory', directoryPath),
readSubdirectory: (directoryPath) => ipcRenderer.invoke('read-subdirectory', directoryPath),
readFile: (filePath) => ipcRenderer.invoke('read-file', filePath),
writeFile: (filePath, content) => ipcRenderer.invoke('write-file', filePath, content),
createNewFile: (directoryPath, fileName) => ipcRenderer.invoke('create-new-file', directoryPath, fileName),
createFolder: (parentPath, folderName) => ipcRenderer.invoke('create-folder', parentPath, folderName),
deleteFile: (filePath) => ipcRenderer.invoke('delete-file', filePath),
deleteFolder: (folderPath) => ipcRenderer.invoke('delete-folder', folderPath),
}
});