From 7a364de1875669850baa3cc0daeee4962631d243 Mon Sep 17 00:00:00 2001
From: Zane <75694352+zanesq@users.noreply.github.com>
Date: Mon, 4 Aug 2025 08:46:53 -0700
Subject: [PATCH] Fix directory switcher not working in active chat sessions
and file browser not defaulting to current session directory path (#3791)
---
ui/desktop/src/components/ChatInput.tsx | 2 +-
.../components/bottom_menu/DirSwitcher.tsx | 12 +----
ui/desktop/src/main.ts | 52 +++++++++++++++++++
3 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/ui/desktop/src/components/ChatInput.tsx b/ui/desktop/src/components/ChatInput.tsx
index 1f15d921a8..13ab9b9de1 100644
--- a/ui/desktop/src/components/ChatInput.tsx
+++ b/ui/desktop/src/components/ChatInput.tsx
@@ -1239,7 +1239,7 @@ export default function ChatInput({
{/* Secondary actions and controls row below input */}
{/* Directory path */}
-
0} className="mr-0" />
+
{/* Attach button */}
diff --git a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
index c51bea91c9..4bf199988d 100644
--- a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
+++ b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
@@ -3,22 +3,14 @@ import { FolderDot } from 'lucide-react';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/Tooltip';
interface DirSwitcherProps {
- hasMessages?: boolean;
className?: string;
}
-export const DirSwitcher: React.FC = ({
- hasMessages = false,
- className = '',
-}) => {
+export const DirSwitcher: React.FC = ({ className = '' }) => {
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
const handleDirectoryChange = async () => {
- if (hasMessages) {
- window.electron.directoryChooser();
- } else {
- window.electron.directoryChooser(true);
- }
+ window.electron.directoryChooser(true);
};
return (
diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts
index 81e828610d..589acd2d4b 100644
--- a/ui/desktop/src/main.ts
+++ b/ui/desktop/src/main.ts
@@ -944,8 +944,60 @@ const buildRecentFilesMenu = () => {
const openDirectoryDialog = async (
replaceWindow: boolean = false
): Promise => {
+ // Get the current working directory from the focused window
+ let defaultPath: string | undefined;
+ const currentWindow = BrowserWindow.getFocusedWindow();
+
+ if (currentWindow) {
+ try {
+ const currentWorkingDir = await currentWindow.webContents.executeJavaScript(
+ `window.appConfig ? window.appConfig.get('GOOSE_WORKING_DIR') : null`
+ );
+
+ if (currentWorkingDir && typeof currentWorkingDir === 'string') {
+ // Verify the directory exists before using it as default
+ try {
+ const stats = fsSync.lstatSync(currentWorkingDir);
+ if (stats.isDirectory()) {
+ defaultPath = currentWorkingDir;
+ }
+ } catch (error) {
+ if (error && typeof error === 'object' && 'code' in error) {
+ const fsError = error as { code?: string; message?: string };
+ if (
+ fsError.code === 'ENOENT' ||
+ fsError.code === 'EACCES' ||
+ fsError.code === 'EPERM'
+ ) {
+ console.warn(
+ `Current working directory not accessible (${fsError.code}): ${currentWorkingDir}, falling back to home directory`
+ );
+ defaultPath = os.homedir();
+ } else {
+ console.warn(
+ `Unexpected filesystem error (${fsError.code}) for directory ${currentWorkingDir}:`,
+ fsError.message
+ );
+ defaultPath = os.homedir();
+ }
+ } else {
+ console.warn(`Unexpected error checking directory ${currentWorkingDir}:`, error);
+ defaultPath = os.homedir();
+ }
+ }
+ }
+ } catch (error) {
+ console.warn('Failed to get current working directory from window:', error);
+ }
+ }
+
+ if (!defaultPath) {
+ defaultPath = os.homedir();
+ }
+
const result = (await dialog.showOpenDialog({
properties: ['openFile', 'openDirectory', 'createDirectory'],
+ defaultPath: defaultPath,
})) as unknown as OpenDialogReturnValue;
if (!result.canceled && result.filePaths.length > 0) {