INNER CODE UNIT · TypeScript
registerConfigHandlers
1095071913/maozi-cloud · maozi-cloud-develop-admin/electron/configs/index.ts:100
export function registerConfigHandlers(): void {
ipcMain.handle('configs:list', async () => {
try {
return { ok: true, data: { configs: listConfigs(), tools: await checkTools() } }
} catch (err) {
return { ok: false, error: (err as Error).message }
}
})
ipcMain.handle('configs:save', async (_e, input: Partial<ConfigEntry>) => {
try {
// 保存后的类型对应的 CLI 未安装时不允许修改(与前端禁用一致,后端兜底)
const resultType = input.id
? (listConfigs().find((c) => c.id === input.id)?.type ?? input.type)
: input.type
// Linux 类型纯凭据存储,不关联 CLI 工具,跳过检测;其余类型需对应 CLI 可用
if (resultType && resultType !== '' && resultType !== 'Linux' && !(await toolExists(resultType))) {
throw new Error(`本机未安装 ${TOOL_BIN[resultType] ?? resultType},不允许修改`)