Files
Aurora-dockside-ddev/src/preload/index.ts
T

35 lines
1.2 KiB
TypeScript
Raw Normal View History

import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import type { DdevProjectDetail, DdevProjectSummary } from '../shared/types'
// Custom APIs for renderer
const api = {
projects: {
list: (): Promise<DdevProjectSummary[]> => ipcRenderer.invoke('projects:list'),
describe: (name: string): Promise<DdevProjectDetail> =>
ipcRenderer.invoke('projects:describe', name),
start: (name: string): Promise<void> => ipcRenderer.invoke('projects:start', name),
stop: (name: string): Promise<void> => ipcRenderer.invoke('projects:stop', name),
restart: (name: string): Promise<void> => ipcRenderer.invoke('projects:restart', name)
}
}
export type Api = typeof api
// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('electron', electronAPI)
contextBridge.exposeInMainWorld('api', api)
} catch (error) {
console.error(error)
}
} else {
// @ts-ignore (define in dts)
window.electron = electronAPI
// @ts-ignore (define in dts)
window.api = api
}