-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreLoad.js
41 lines (36 loc) · 1.31 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
const { contextBridge } = require('electron')
const fs = require('fs')
const path = require('path')
const child_process = require('child_process')
contextBridge.exposeInMainWorld('defined_functions', {
isPathDirectory: (path) => fs.lstatSync(path).isDirectory(),
desktopPath: () => require('os').homedir().replaceAll('\\', '/') + '/Desktop',
writeToFile: (file_path, newValue) => {
fs.readFile(file_path, 'utf-8', function(error, data) {
if (error) {
console.error(error)
return
}
fs.writeFile(file_path, newValue, 'utf-8', function(error, data) {
if (error) {
console.error(error)
return
}
})
})
}
})
contextBridge.exposeInMainWorld('fs', {
readdir: (...args) => fs.readdir(...args),
existsSync: (...args) => fs.existsSync(...args),
readFile: (...args) => fs.readFile(...args),
mkdirSync: (...args) => fs.mkdirSync(...args),
writeFileSync: (...args) => fs.writeFileSync(...args)
})
contextBridge.exposeInMainWorld('path', {
join: (...args) => path.join(...args),
dirname: (...args) => path.dirname(...args)
})
contextBridge.exposeInMainWorld('child_process', {
exec: (...args) => child_process.exec(...args)
})