mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
fix: update getDefaultDocumentsPath to use window.electronAPI for Electron mode
- Removed dependency on getElectronAPI and directly accessed window.electronAPI for retrieving the documents path in Electron mode. - Added handling for web mode to return null when the documents path cannot be accessed. - Included logging for the resolved documents path to aid in debugging.
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import { createLogger } from '@automaker/utils/logger';
|
import { createLogger } from '@automaker/utils/logger';
|
||||||
import { getHttpApiClient } from './http-api-client';
|
import { getHttpApiClient } from './http-api-client';
|
||||||
import { getElectronAPI } from './electron';
|
|
||||||
import { useAppStore } from '@/store/app-store';
|
import { useAppStore } from '@/store/app-store';
|
||||||
|
|
||||||
const logger = createLogger('WorkspaceConfig');
|
const logger = createLogger('WorkspaceConfig');
|
||||||
@@ -33,9 +32,17 @@ function joinPath(...parts: string[]): string {
|
|||||||
*/
|
*/
|
||||||
async function getDefaultDocumentsPath(): Promise<string | null> {
|
async function getDefaultDocumentsPath(): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const api = getElectronAPI();
|
// In Electron mode, use the native getPath API directly from the preload script
|
||||||
const documentsPath = await api.getPath('documents');
|
// This returns the actual system Documents folder (e.g., C:\Users\<user>\Documents on Windows)
|
||||||
|
// Note: The HTTP client's getPath returns incorrect Unix-style paths for 'documents'
|
||||||
|
if (typeof window !== 'undefined' && (window as any).electronAPI?.getPath) {
|
||||||
|
const documentsPath = await (window as any).electronAPI.getPath('documents');
|
||||||
return joinPath(documentsPath, 'Automaker');
|
return joinPath(documentsPath, 'Automaker');
|
||||||
|
}
|
||||||
|
|
||||||
|
// In web mode (no Electron), we can't access the user's Documents folder
|
||||||
|
// Return null to let the caller use other fallback mechanisms (like server's DATA_DIR)
|
||||||
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to get documents path:', error);
|
logger.error('Failed to get documents path:', error);
|
||||||
return null;
|
return null;
|
||||||
@@ -76,6 +83,7 @@ export async function getDefaultWorkspaceDirectory(): Promise<string | null> {
|
|||||||
|
|
||||||
// Try to get Documents/Automaker
|
// Try to get Documents/Automaker
|
||||||
const documentsPath = await getDefaultDocumentsPath();
|
const documentsPath = await getDefaultDocumentsPath();
|
||||||
|
logger.info('Default documentsPath resolved to:', documentsPath);
|
||||||
if (documentsPath) {
|
if (documentsPath) {
|
||||||
return documentsPath;
|
return documentsPath;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user