stop replacing chat window when changing working directory (#4200)
This commit is contained in:
+5
-44
@@ -953,9 +953,7 @@ const buildRecentFilesMenu = () => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const openDirectoryDialog = async (
|
const openDirectoryDialog = async (): Promise<OpenDialogReturnValue> => {
|
||||||
replaceWindow: boolean = false
|
|
||||||
): Promise<OpenDialogReturnValue> => {
|
|
||||||
// Get the current working directory from the focused window
|
// Get the current working directory from the focused window
|
||||||
let defaultPath: string | undefined;
|
let defaultPath: string | undefined;
|
||||||
const currentWindow = BrowserWindow.getFocusedWindow();
|
const currentWindow = BrowserWindow.getFocusedWindow();
|
||||||
@@ -1033,45 +1031,8 @@ const openDirectoryDialog = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
addRecentDir(dirToAdd);
|
addRecentDir(dirToAdd);
|
||||||
const currentWindow = BrowserWindow.getFocusedWindow();
|
// Create a new window with the selected directory
|
||||||
|
await createChat(app, undefined, dirToAdd);
|
||||||
if (replaceWindow && currentWindow) {
|
|
||||||
// Replace current window with new one
|
|
||||||
await createChat(app, undefined, dirToAdd);
|
|
||||||
currentWindow.close();
|
|
||||||
} else {
|
|
||||||
// Update the working directory in the current window's localStorage
|
|
||||||
if (currentWindow) {
|
|
||||||
try {
|
|
||||||
const updateConfigScript = `
|
|
||||||
try {
|
|
||||||
const currentConfig = JSON.parse(localStorage.getItem('gooseConfig') || '{}');
|
|
||||||
const updatedConfig = {
|
|
||||||
...currentConfig,
|
|
||||||
GOOSE_WORKING_DIR: '${dirToAdd.replace(/'/g, "\\'")}',
|
|
||||||
};
|
|
||||||
localStorage.setItem('gooseConfig', JSON.stringify(updatedConfig));
|
|
||||||
|
|
||||||
// Trigger a config update event so the UI can refresh
|
|
||||||
window.dispatchEvent(new CustomEvent('goose-config-updated', {
|
|
||||||
detail: { GOOSE_WORKING_DIR: '${dirToAdd.replace(/'/g, "\\'")}' }
|
|
||||||
}));
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to update working directory in localStorage:', e);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
await currentWindow.webContents.executeJavaScript(updateConfigScript);
|
|
||||||
console.log(`Updated working directory to: ${dirToAdd}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to update working directory:', error);
|
|
||||||
// Fallback: create new window
|
|
||||||
await createChat(app, undefined, dirToAdd);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No current window, create new one
|
|
||||||
await createChat(app, undefined, dirToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -1110,8 +1071,8 @@ ipcMain.on('react-ready', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle directory chooser
|
// Handle directory chooser
|
||||||
ipcMain.handle('directory-chooser', (_event, replace: boolean = false) => {
|
ipcMain.handle('directory-chooser', (_event) => {
|
||||||
return openDirectoryDialog(replace);
|
return openDirectoryDialog();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle scheduling engine settings
|
// Handle scheduling engine settings
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ const electronAPI: ElectronAPI = {
|
|||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
hideWindow: () => ipcRenderer.send('hide-window'),
|
hideWindow: () => ipcRenderer.send('hide-window'),
|
||||||
directoryChooser: (replace?: boolean) => ipcRenderer.invoke('directory-chooser', replace),
|
directoryChooser: () => ipcRenderer.invoke('directory-chooser'),
|
||||||
createChatWindow: (
|
createChatWindow: (
|
||||||
query?: string,
|
query?: string,
|
||||||
dir?: string,
|
dir?: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user