2024-07-24 21:37:29 -04:00
|
|
|
import { ipcRenderer, contextBridge } from 'electron'
|
2024-07-23 21:10:21 -04:00
|
|
|
import path from 'path'
|
2024-07-24 21:37:29 -04:00
|
|
|
import fs from 'node:fs/promises'
|
|
|
|
import packageJson from '../../package.json'
|
2024-07-23 21:10:21 -04:00
|
|
|
|
2024-07-24 21:37:29 -04:00
|
|
|
const readFile = (path: string) => fs.readFile(path, 'utf-8')
|
|
|
|
const readdir = (path: string) => fs.readdir(path, 'utf-8')
|
|
|
|
const exists = (path: string) =>
|
|
|
|
new Promise((resolve, reject) =>
|
|
|
|
fs.stat(path, (err, data) => {
|
|
|
|
if (err) return reject(err.code)
|
|
|
|
return resolve(data)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const getPath = async (name: string) => ipcRenderer.invoke('app.getPath', name)
|
2024-07-23 17:16:26 -04:00
|
|
|
|
2024-07-24 21:37:29 -04:00
|
|
|
contextBridge.exposeInMainWorld('electron', {
|
|
|
|
readFile,
|
|
|
|
readdir,
|
|
|
|
path,
|
|
|
|
exists,
|
|
|
|
mkdir: fs.mkdir,
|
|
|
|
getPath,
|
|
|
|
packageJson,
|
2024-07-23 21:10:21 -04:00
|
|
|
})
|