-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
29 lines (28 loc) · 1015 Bytes
/
Copy pathpreload.js
File metadata and controls
29 lines (28 loc) · 1015 Bytes
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
const fs = require('fs');
const path = require('path');
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('myAPI', {
listFiles: (folderPath) => {
try {
folderPath = path.join(__dirname, "src", folderPath);
return fs.readdirSync(folderPath).filter(file => fs.statSync(path.join(folderPath, file)).isFile());
} catch (err) {
console.error('Error reading files:', err);
return [];
}
},
listFolders: (folderPath) => {
try {
folderPath = path.join(__dirname, "src", folderPath);
return fs.readdirSync(folderPath).filter(file => !fs.statSync(path.join(folderPath, file)).isFile());
} catch (err) {
console.error('Error reading folders:', err);
return [];
}
},
readFile: (filePath, options) => fs.readFile(filePath, options),
joinPath: (...args) => path.join(...args),
dirname: () => __dirname,
showOpenDialog: (title, exts) =>
ipcRenderer.invoke('show-open-dialog', { title, exts })
});