Files
modeling-app/src/lib/electron.ts

26 lines
676 B
TypeScript
Raw Normal View History

2024-07-24 21:37:29 -04:00
import { ipcRenderer, contextBridge } from 'electron'
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-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-24 21:37:29 -04:00
contextBridge.exposeInMainWorld('electron', {
readFile,
readdir,
path,
exists,
mkdir: fs.mkdir,
getPath,
packageJson,
})