Most FS functions work now

This commit is contained in:
49lf
2024-07-30 15:58:27 -04:00
parent 397eb9bf5a
commit 1a1e358238
23 changed files with 235 additions and 138 deletions

View File

@ -3,7 +3,11 @@ import path from 'path'
import fs from 'node:fs/promises'
import packageJson from '../../package.json'
const open = (args: any) => ipcRenderer.invoke('dialog', args)
const showInFolder = (path: string) => ipcRenderer.invoke('shell.showItemInFolder', path)
const readFile = (path: string) => fs.readFile(path, 'utf-8')
const rename = (prev: string, next: string) => fs.rename(prev, next)
const writeFile = (path: string, data: string) =>
fs.writeFile(path, data, 'utf-8')
const readdir = (path: string) => fs.readdir(path, 'utf-8')
@ -27,13 +31,21 @@ const exposeProcessEnv = (varName: string) => {
import('@kittycad/lib').then((kittycad) => {
contextBridge.exposeInMainWorld('electron', {
// Passing fs directly is not recommended since it gives a lot of power
// to the browser side / potential malicious code. We restrict what is
// exported.
readFile,
writeFile,
readdir,
rename,
rm: fs.rm,
path,
stat,
statIsDirectory,
mkdir: fs.mkdir,
// opens a dialog
open,
showInFolder,
getPath,
packageJson,
platform: process.platform,