diff --git a/src/app/api/open-directory/route.ts b/src/app/api/open-directory/route.ts index 97867561..1b6ad731 100644 --- a/src/app/api/open-directory/route.ts +++ b/src/app/api/open-directory/route.ts @@ -1,10 +1,10 @@ import { NextRequest, NextResponse } from "next/server"; -import { exec } from "child_process"; +import { execFile } from "child_process"; import { promisify } from "util"; import os from "os"; -const execAsync = promisify(exec); +const execFileAsync = promisify(execFile); export async function POST(req: NextRequest) { try { @@ -19,24 +19,29 @@ export async function POST(req: NextRequest) { } let command = ""; + let args: string[] = []; const platform = os.platform(); switch (platform) { case "darwin": - command = `open "${path}"`; + command = "open"; + args = [path]; break; case "win32": - command = `explorer "${path}"`; + command = "explorer"; + args = [path]; break; case "linux": - command = `xdg-open "${path}"`; + command = "xdg-open"; + args = [path]; break; default: - // Fallback for other Unix-like systems, might not work everywhere - command = `xdg-open "${path}"`; + // Fallback for other Unix-like systems + command = "xdg-open"; + args = [path]; } - await execAsync(command); + await execFileAsync(command, args); return NextResponse.json({ success: true }); } catch (error) { diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 81823089..86d1e452 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -81,15 +81,24 @@ export function Header() { if (!saveDirectoryPath) return; try { - await fetch("/api/open-directory", { + 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."); } }; @@ -142,25 +151,27 @@ export function Header() { )} - + + + + + )}