Files
paseo/packages/desktop/src/features/editor-targets/ipc.ts
T
Mohamed Boudra f4509fe044 Open files in more installed editors (#2119)
* feat(desktop): open files in more installed editors

Detect bundled app commands as well as PATH launchers and preserve file positions through editor-specific launches.

* fix(desktop): preserve editor target compatibility

Keep existing file-manager preference ids, retain project context for file launches, and recognize Windows 64-bit IDE commands.
2026-07-16 14:39:55 +02:00

38 lines
1.3 KiB
TypeScript

import { ipcMain } from "electron";
import { z } from "zod";
import { listAvailableEditorTargets, openEditorTarget } from "./registry.js";
import { createEditorTargetRuntime } from "./runtime.js";
import type { EditorTarget, EditorTargetRuntime } from "./target.js";
interface IpcHandlerRegistry {
handle(channel: string, listener: (event: unknown, ...args: unknown[]) => unknown): void;
}
const EditorTargetLaunchInputSchema = z.object({
editorId: z.string().trim().min(1),
workspacePath: z.string().trim().min(1),
filePath: z.string().trim().min(1).optional(),
line: z.number().int().positive().optional(),
column: z.number().int().positive().optional(),
});
export function registerEditorTargetHandlers(
options: {
ipc?: IpcHandlerRegistry;
runtime?: EditorTargetRuntime;
targets?: readonly EditorTarget[];
} = {},
): void {
const ipc = options.ipc ?? ipcMain;
const runtime = options.runtime ?? createEditorTargetRuntime();
ipc.handle("paseo:editor:listTargets", () =>
listAvailableEditorTargets(runtime, options.targets),
);
ipc.handle("paseo:editor:openTarget", async (_event, payload: unknown) => {
const input = EditorTargetLaunchInputSchema.parse(payload);
await openEditorTarget(input, runtime, options.targets);
});
}