From a7b671444186fb8cfcc3c1c18de3d71ebd691c33 Mon Sep 17 00:00:00 2001 From: CatoPaus Date: Thu, 25 Dec 2025 14:54:09 +0100 Subject: [PATCH 1/2] feat: add open working directory button to header --- src/app/api/open-directory/route.ts | 49 +++++++++++++++++++++++++++++ src/components/Header.tsx | 35 +++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/app/api/open-directory/route.ts diff --git a/src/app/api/open-directory/route.ts b/src/app/api/open-directory/route.ts new file mode 100644 index 0000000..9786756 --- /dev/null +++ b/src/app/api/open-directory/route.ts @@ -0,0 +1,49 @@ + +import { NextRequest, NextResponse } from "next/server"; +import { exec } from "child_process"; +import { promisify } from "util"; +import os from "os"; + +const execAsync = promisify(exec); + +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 = ""; + const platform = os.platform(); + + switch (platform) { + case "darwin": + command = `open "${path}"`; + break; + case "win32": + command = `explorer "${path}"`; + break; + case "linux": + command = `xdg-open "${path}"`; + break; + default: + // Fallback for other Unix-like systems, might not work everywhere + command = `xdg-open "${path}"`; + } + + await execAsync(command); + + 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 } + ); + } +} diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 9c0e722..8182308 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -77,6 +77,22 @@ export function Header() { }, 50); }; + const handleOpenDirectory = async () => { + if (!saveDirectoryPath) return; + + try { + await fetch("/api/open-directory", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ path: saveDirectoryPath }), + }); + } catch (error) { + console.error("Failed to open directory:", error); + } + }; + return ( <> )} + - + + + + + )}