New project flow: native directory picker, project name (auto-filled from folder name), project type selector (Auto-detect plus common CMS/framework types), optional docroot, and a "start after creating" checkbox. Runs ddev config with cwd = the chosen directory (streamed through the existing commandRunner), then reuses the existing useStartProject() mutation for the start step rather than inventing multi-phase operation semantics — ddev config registers the project by name, so a plain `ddev start <name>` works identically to starting any other project afterward. Scoped down from the original app's wizard: skipped scaffolding a fresh CMS codebase (composer create-project / wp core download / etc.) since each framework needs different install commands — this covers project registration + config + start, with ddev's own --auto/--project-type detection handling "auto-detect for existing folders" for free (no custom detection heuristics needed). Verified end-to-end against the real scratch environment: called the create.configure IPC directly (the picker itself opens a native OS dialog CDP can't drive, same constraint as import/export in step 4) with a real target directory, confirmed the generated .ddev/config.yaml has the correct name/type/docroot, confirmed the new project appears in the sidebar via the existing polling within one refresh cycle, and verified the modal's form guards (Create disabled until a directory is chosen) and all type-selector options render correctly. Cleaned up via `ddev delete`.
121 lines
5.2 KiB
TypeScript
121 lines
5.2 KiB
TypeScript
import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'
|
|
import { electronAPI } from '@electron-toolkit/preload'
|
|
import type {
|
|
DdevAddonRegistryEntry,
|
|
DdevInstalledAddon,
|
|
DdevProjectDetail,
|
|
DdevProjectSummary,
|
|
DdevSnapshot,
|
|
LogDataEvent,
|
|
LogExitEvent,
|
|
TerminalDataEvent,
|
|
TerminalExitEvent
|
|
} 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: (operationId: string, name: string): Promise<void> =>
|
|
ipcRenderer.invoke('projects:start', operationId, name),
|
|
stop: (operationId: string, name: string): Promise<void> =>
|
|
ipcRenderer.invoke('projects:stop', operationId, name),
|
|
restart: (operationId: string, name: string): Promise<void> =>
|
|
ipcRenderer.invoke('projects:restart', operationId, name)
|
|
},
|
|
terminal: {
|
|
cancel: (operationId: string): Promise<boolean> =>
|
|
ipcRenderer.invoke('terminal:cancel', operationId),
|
|
onData: (callback: (event: TerminalDataEvent) => void): (() => void) => {
|
|
const listener = (_event: IpcRendererEvent, data: TerminalDataEvent): void => callback(data)
|
|
ipcRenderer.on('terminal:data', listener)
|
|
return () => ipcRenderer.removeListener('terminal:data', listener)
|
|
},
|
|
onExit: (callback: (event: TerminalExitEvent) => void): (() => void) => {
|
|
const listener = (_event: IpcRendererEvent, data: TerminalExitEvent): void => callback(data)
|
|
ipcRenderer.on('terminal:exit', listener)
|
|
return () => ipcRenderer.removeListener('terminal:exit', listener)
|
|
}
|
|
},
|
|
database: {
|
|
listSnapshots: (name: string, approot: string): Promise<DdevSnapshot[]> =>
|
|
ipcRenderer.invoke('database:listSnapshots', name, approot),
|
|
createSnapshot: (operationId: string, approot: string, snapshotName?: string): Promise<void> =>
|
|
ipcRenderer.invoke('database:createSnapshot', operationId, approot, snapshotName),
|
|
restoreSnapshot: (operationId: string, approot: string, snapshotName: string): Promise<void> =>
|
|
ipcRenderer.invoke('database:restoreSnapshot', operationId, approot, snapshotName),
|
|
deleteSnapshot: (operationId: string, approot: string, snapshotName: string): Promise<void> =>
|
|
ipcRenderer.invoke('database:deleteSnapshot', operationId, approot, snapshotName),
|
|
importFile: (operationId: string, approot: string, filePath: string): Promise<void> =>
|
|
ipcRenderer.invoke('database:importFile', operationId, approot, filePath),
|
|
exportFile: (operationId: string, approot: string, filePath: string): Promise<void> =>
|
|
ipcRenderer.invoke('database:exportFile', operationId, approot, filePath),
|
|
pickImportFile: (): Promise<string | null> => ipcRenderer.invoke('database:pickImportFile'),
|
|
pickExportPath: (defaultFileName: string): Promise<string | null> =>
|
|
ipcRenderer.invoke('database:pickExportPath', defaultFileName)
|
|
},
|
|
addons: {
|
|
listRegistry: (): Promise<DdevAddonRegistryEntry[]> =>
|
|
ipcRenderer.invoke('addons:listRegistry'),
|
|
listInstalled: (name: string): Promise<DdevInstalledAddon[]> =>
|
|
ipcRenderer.invoke('addons:listInstalled', name),
|
|
install: (operationId: string, name: string, addonRepo: string): Promise<void> =>
|
|
ipcRenderer.invoke('addons:install', operationId, name, addonRepo),
|
|
remove: (operationId: string, name: string, addonName: string): Promise<void> =>
|
|
ipcRenderer.invoke('addons:remove', operationId, name, addonName)
|
|
},
|
|
logs: {
|
|
start: (operationId: string, name: string, service: string): Promise<void> =>
|
|
ipcRenderer.invoke('logs:start', operationId, name, service),
|
|
onData: (callback: (event: LogDataEvent) => void): (() => void) => {
|
|
const listener = (_event: IpcRendererEvent, data: LogDataEvent): void => callback(data)
|
|
ipcRenderer.on('logs:data', listener)
|
|
return () => ipcRenderer.removeListener('logs:data', listener)
|
|
},
|
|
onExit: (callback: (event: LogExitEvent) => void): (() => void) => {
|
|
const listener = (_event: IpcRendererEvent, data: LogExitEvent): void => callback(data)
|
|
ipcRenderer.on('logs:exit', listener)
|
|
return () => ipcRenderer.removeListener('logs:exit', listener)
|
|
}
|
|
},
|
|
create: {
|
|
pickDirectory: (): Promise<string | null> => ipcRenderer.invoke('create:pickDirectory'),
|
|
configure: (
|
|
operationId: string,
|
|
directory: string,
|
|
projectName: string,
|
|
projectType: string,
|
|
docroot: string
|
|
): Promise<void> =>
|
|
ipcRenderer.invoke(
|
|
'create:configure',
|
|
operationId,
|
|
directory,
|
|
projectName,
|
|
projectType,
|
|
docroot
|
|
)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|