Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: add support for opening project folders in various code editors

konstantin-paulusc6a5c721e46a
diff --git a/apps/desktop/src/editors.ts b/apps/desktop/src/editors.ts
new file mode 100644
index 00000000..0112590c
--- /dev/null
+++ b/apps/desktop/src/editors.ts
@@ -0,0 +1,64 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Code editors a project folder can be opened in. A project is a folder of
+// JSX, so editing it by hand is a real way of working on it, and the app's
+// watcher puts whatever the editor saves on the canvas.
+
+import { app } from "electron";
+import { execFile, spawn } from "node:child_process";
+import { isAbsolute } from "node:path";
+
+export type EditorId = "vscode" | "cursor" | "zed";
+
+export type EditorInfo = { id: EditorId; label: string };
+
+/**
+ * The editors offered, in menu order. Each is found by the URL scheme it
+ * registers with the OS when installed: asking who handles it answers both
+ * whether the editor is there and where, on macOS and Windows alike, without
+ * knowing where anyone keeps their applications.
+ */
+const EDITORS: Array<EditorInfo & { protocol: string }> = [
+ { id: "vscode", label: "VS Code", protocol: "vscode://" },
+ { id: "cursor", label: "Cursor", protocol: "cursor://" },
+ { id: "zed", label: "Zed", protocol: "zed://" },
+];
+
+/** Where the app handling `protocol` lives (the .app on macOS, the .exe on Windows), or null when none does. */
+async function handlerPath(protocol: string): Promise<string | null> {
+ try {
+ return (await app.getApplicationInfoForProtocol(protocol)).path || null;
+ } catch {
+ return null;
+ }
+}
+
+/** The editors installed here, in menu order. */
+export async function installedEditors(): Promise<EditorInfo[]> {
+ const found = await Promise.all(EDITORS.map(async (editor) => ((await handlerPath(editor.protocol)) ? editor : null)));
+ return found.filter((editor) => editor !== null).map(({ id, label }) => ({ id, label }));
+}
+
+/** Opens the folder `dir` in the editor `id`. */
+export async function openInEditor(id: EditorId, dir: string): Promise<void> {
+ const editor = EDITORS.find((candidate) => candidate.id === id);
+ if (!editor) throw new Error(`Unknown editor "${id}".`);
+ if (!isAbsolute(dir)) throw new Error(`The folder must be an absolute path (got "${dir}").`);
+
+ const path = await handlerPath(editor.protocol);
+ if (!path) throw new Error(`${editor.label} is not installed.`);
+
+ if (process.platform === "darwin") {
+ await new Promise<void>((resolve, reject) => {
+ execFile("/usr/bin/open", ["-a", path, dir], (error) => (error ? reject(error) : resolve()));
+ });
+ return;
+ }
+
+ // Windows: the editor's own executable takes a folder to open, and outlives the app.
+ const child = spawn(path, [dir], { detached: true, stdio: "ignore" });
+ child.on("error", (error) => console.error(`[editors] could not start ${editor.label}:`, error));
+ child.unref();
+}
diff --git a/apps/desktop/src/main-channels.ts b/apps/desktop/src/main-channels.ts
index 2aa83e0d..d5463fd3 100644
--- a/apps/desktop/src/main-channels.ts
+++ b/apps/desktop/src/main-channels.ts
@@ -12,6 +12,7 @@
import type { LogEntry, ScreenshotResult } from "@diffusionstudio/dapi";
import type { SourceEdit, WriteResult } from "./edit-types";
import type { AgentId } from "./mcp-config";
+import type { EditorId, EditorInfo } from "./editors";
export const MAIN_WIRE = {
REQUEST: "main:request",
@@ -30,6 +31,8 @@ export const MAIN_CHANNELS = {
// Renderer→Main requests
APP_OPEN_EXTERNAL: "app:open-external",
APP_SHOW_IN_FOLDER: "app:show-in-folder",
+ APP_EDITORS_LIST: "app:editors-list",
+ APP_OPEN_IN_EDITOR: "app:open-in-editor",
ANALYTICS_CONFIGURE: "analytics:configure",
AUTH_GET_PENDING_CALLBACK: "auth:get-pending-callback",
CHECKOUT_GET_PENDING_CALLBACK: "checkout:get-pending-callback",
@@ -116,6 +119,7 @@ export type CompileResult =
export type { SourceEdit, WriteResult };
export type { AgentId };
+export type { EditorId, EditorInfo };
// One agent the settings page lists: whether it is set up on this machine,
// whether its config already carries the app's MCP entry, and — for the
@@ -224,6 +228,15 @@ export type MainRequestMap = {
request: { path: string };
response: void;
};
+ // The code editors installed here that a folder can be opened in.
+ [MAIN_CHANNELS.APP_EDITORS_LIST]: {
+ request: void;
+ response: EditorInfo[];
+ };
+ [MAIN_CHANNELS.APP_OPEN_IN_EDITOR]: {
+ request: { id: EditorId; dir: string };
+ response: void;
+ };
[MAIN_CHANNELS.LOGS_GET]: { request: void; response: LogEntry[] };
[MAIN_CHANNELS.PROJECTS_PICK_FOLDER]: {
request: void;
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 41261aed..f5d2e64d 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -16,6 +16,7 @@ import { cliStatus, installCli, refreshCliShim, uninstallCli } from "./cli-insta
import { applyMcp, healMcpRegistrations, mcpStatus } from "./mcp-install";
import { configureAnalytics, countCanvasEdits, startAnalytics, track } from "./analytics";
import { setupAppMenu } from "./menu";
+import { installedEditors, openInEditor } from "./editors";
import { AppTray } from "./tray";
import { WindowHost } from "./window-host";
import { handleSquirrelEvent } from "./squirrel";
@@ -355,6 +356,8 @@ if (squirrelLaunch) {
mainBridge.handle(MAIN_CHANNELS.APP_OPEN_EXTERNAL, ({ url }) => shell.openExternal(url));
mainBridge.handle(MAIN_CHANNELS.APP_SHOW_IN_FOLDER, ({ path }) => shell.showItemInFolder(path));
+ mainBridge.handle(MAIN_CHANNELS.APP_EDITORS_LIST, () => installedEditors());
+ mainBridge.handle(MAIN_CHANNELS.APP_OPEN_IN_EDITOR, ({ id, dir }) => openInEditor(id, dir));
mainBridge.handle(MAIN_CHANNELS.ANALYTICS_CONFIGURE, (config) => configureAnalytics(config));
mainBridge.handle(MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK, () =>
takePendingDeepLink(MAIN_CHANNELS.AUTH_CALLBACK),
diff --git a/apps/web/src/components/sidebar-left/project-menu/folder-menu.tsx b/apps/web/src/components/sidebar-left/project-menu/folder-menu.tsx
index fc8be9ad..bccc5c3f 100644
--- a/apps/web/src/components/sidebar-left/project-menu/folder-menu.tsx
+++ b/apps/web/src/components/sidebar-left/project-menu/folder-menu.tsx
@@ -2,17 +2,24 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+import { For, Show, createResource } from "solid-js";
import { toast } from "somoto";
import {
DropdownMenuGroup,
DropdownMenuItem,
+ DropdownMenuSeparator,
DropdownMenuShortcut,
} from "@/components/ui/dropdown-menu";
import { useProject } from "@/context/project";
+import { listEditors, openInEditor, revealPath } from "@/lib/shell";
+import { isWindowsDesktop } from "@/projects";
+
+import type { EditorInfo } from "@/lib/shell";
/** What can be done with the project's folder. */
export function FolderMenu() {
const project = useProject();
+ const [editors] = createResource(listEditors, { initialValue: [] });
const handleSaveFolder = async () => {
try {
@@ -22,12 +29,47 @@ export function FolderMenu() {
}
};
+ const handleReveal = async () => {
+ try {
+ await revealPath(project.dir());
+ } catch (e) {
+ toast.error("Failed to show the folder", { description: (e as Error).message });
+ }
+ };
+
+ const handleOpenInEditor = async (editor: EditorInfo) => {
+ try {
+ await openInEditor(editor.id, project.dir());
+ } catch (e) {
+ toast.error(`Failed to open in ${editor.label}`, { description: (e as Error).message });
+ }
+ };
+
return (
- <DropdownMenuGroup>
- <DropdownMenuItem onSelect={handleSaveFolder} disabled={!project.draft()}>
- Save folder...
- <DropdownMenuShortcut>⌘S</DropdownMenuShortcut>
- </DropdownMenuItem>
- </DropdownMenuGroup>
+ <>
+ <DropdownMenuGroup>
+ <DropdownMenuItem onSelect={handleSaveFolder} disabled={!project.draft()}>
+ Save folder...
+ <DropdownMenuShortcut>⌘S</DropdownMenuShortcut>
+ </DropdownMenuItem>
+ <DropdownMenuItem onSelect={handleReveal}>
+ {isWindowsDesktop() ? "Show in Explorer" : "Show in Finder"}
+ </DropdownMenuItem>
+ </DropdownMenuGroup>
+
+ <Show when={editors().length > 0}>
+ <DropdownMenuSeparator />
+
+ <DropdownMenuGroup>
+ <For each={editors()}>
+ {(editor) => (
+ <DropdownMenuItem onSelect={() => handleOpenInEditor(editor)}>
+ Open in {editor.label}
+ </DropdownMenuItem>
+ )}
+ </For>
+ </DropdownMenuGroup>
+ </Show>
+ </>
);
}
diff --git a/apps/web/src/lib/shell.ts b/apps/web/src/lib/shell.ts
index 65a9291c..c4aeaf33 100644
--- a/apps/web/src/lib/shell.ts
+++ b/apps/web/src/lib/shell.ts
@@ -9,6 +9,10 @@
import { MAIN_CHANNELS } from "@desktop/main-channels";
import { mainBridge } from "@/lib/ipc";
+import type { EditorId, EditorInfo } from "@desktop/main-channels";
+
+export type { EditorId, EditorInfo };
+
/**
* Reveals a file or folder in the OS file manager — Finder on macOS, Explorer
* on Windows — selecting it inside its parent folder.
@@ -17,3 +21,25 @@ export async function revealPath(path: string): Promise<void> {
if (!window.desktop || !path) return;
await mainBridge.call(MAIN_CHANNELS.APP_SHOW_IN_FOLDER, { path });
}
+
+// Asked once per session: installing an editor while the app runs is rare
+// enough to wait for the next launch, and the menu listing them should not
+// fill in a beat after it opens.
+let editors: Promise<EditorInfo[]> | undefined;
+
+/** The code editors installed here that a folder can be opened in; none off the desktop. */
+export function listEditors(): Promise<EditorInfo[]> {
+ if (!window.desktop) return Promise.resolve([]);
+ editors ??= mainBridge.call(MAIN_CHANNELS.APP_EDITORS_LIST, undefined).catch((error) => {
+ console.warn("[shell] could not list editors", error);
+ editors = undefined;
+ return [];
+ });
+ return editors;
+}
+
+/** Opens the folder `dir` in the editor `id`. */
+export async function openInEditor(id: EditorId, dir: string): Promise<void> {
+ if (!window.desktop || !dir) return;
+ await mainBridge.call(MAIN_CHANNELS.APP_OPEN_IN_EDITOR, { id, dir });
+}