Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/app/api/open-directory/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

import { NextRequest, NextResponse } from "next/server";
import { execFile } from "child_process";
import { promisify } from "util";
import os from "os";

const execFileAsync = promisify(execFile);

export async function POST(req: NextRequest) {
try {
const body = await req.json();
const { path } = body;

if (!path) {
return NextResponse.json(
{ success: false, error: "Path is required" },
{ status: 400 }
);
}

let command = "";
let args: string[] = [];
const platform = os.platform();

switch (platform) {
case "darwin":
command = "open";
args = [path];
break;
case "win32":
command = "explorer";
args = [path];
break;
case "linux":
command = "xdg-open";
args = [path];
break;
default:
// Fallback for other Unix-like systems
command = "xdg-open";
args = [path];
}

await execFileAsync(command, args);

return NextResponse.json({ success: true });
} catch (error) {
console.error("Failed to open directory:", error);
return NextResponse.json(
{ success: false, error: "Failed to open directory" },
{ status: 500 }
);
}
}
46 changes: 46 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ export function Header() {
}, 50);
};

const handleOpenDirectory = async () => {
if (!saveDirectoryPath) return;

try {
const response = await fetch("/api/open-directory", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ path: saveDirectoryPath }),
});

const result = await response.json();

if (!response.ok || !result.success) {
console.error("Failed to open directory:", result.error);
alert(`Failed to open project folder: ${result.error || "Unknown error"}`);
return;
}
} catch (error) {
console.error("Failed to open directory:", error);
alert("Failed to open project folder. Please try again.");
}
};

return (
<>
<ProjectSetupModal
Expand Down Expand Up @@ -126,6 +151,27 @@ export function Header() {
<span className="absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500" />
)}
</button>
{saveDirectoryPath && (
<button
onClick={handleOpenDirectory}
className="p-1 text-neutral-400 hover:text-neutral-200 transition-colors"
title="Open Project Folder"
>
<svg
className="w-4 h-4"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z"
/>
</svg>
</button>
)}
<button
onClick={handleOpenSettings}
className="p-1 text-neutral-400 hover:text-neutral-200 transition-colors"
Expand Down