2026-08-02 23:31:45 -05:00
|
|
|
import { contextBridge, ipcRenderer } from 'electron'
|
2026-08-02 23:16:26 -05:00
|
|
|
import { electronAPI } from '@electron-toolkit/preload'
|
2026-08-02 23:31:45 -05:00
|
|
|
import type { DdevProjectDetail, DdevProjectSummary } from '../shared/types'
|
2026-08-02 23:16:26 -05:00
|
|
|
|
|
|
|
|
// Custom APIs for renderer
|
2026-08-02 23:31:45 -05:00
|
|
|
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
|
2026-08-02 23:16:26 -05:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|