35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { contextBridge, ipcRenderer } from 'electron'
|
|
|
|
const api = {
|
|
ping: () => ipcRenderer.invoke('app:ping'),
|
|
workspace: {
|
|
pick: () => ipcRenderer.invoke('workspace:pick') as Promise<string | null>,
|
|
get: () => ipcRenderer.invoke('workspace:get') as Promise<string | null>,
|
|
clear: () => ipcRenderer.invoke('workspace:clear') as Promise<null>,
|
|
init: (root: string) => ipcRenderer.invoke('workspace:init', root) as Promise<true>
|
|
},
|
|
env: {
|
|
read: (root: string) => ipcRenderer.invoke('env:read', root) as Promise<any>,
|
|
write: (root: string, data: any) => ipcRenderer.invoke('env:write', root, data) as Promise<true>
|
|
},
|
|
apiProject: {
|
|
read: (root: string) => ipcRenderer.invoke('api:project:read', root) as Promise<any>,
|
|
write: (root: string, data: any) => ipcRenderer.invoke('api:project:write', root, data) as Promise<true>
|
|
},
|
|
api: {
|
|
read: (root: string, relativePath: string) =>
|
|
ipcRenderer.invoke('api:read', root, relativePath) as Promise<any>,
|
|
write: (root: string, relativePath: string, data: any) =>
|
|
ipcRenderer.invoke('api:write', root, relativePath, data) as Promise<true>,
|
|
create: (root: string, relativeDir: string, apiData: any) =>
|
|
ipcRenderer.invoke('api:create', root, relativeDir, apiData) as Promise<{ id: string; filePath: string }>
|
|
},
|
|
shell: {
|
|
openDir: (dir: string) => ipcRenderer.invoke('shell:openDir', dir) as Promise<true>
|
|
}
|
|
}
|
|
|
|
contextBridge.exposeInMainWorld('xs', api)
|
|
|
|
export type XsApi = typeof api
|