diff --git a/src/main/services/FileStorage.ts b/src/main/services/FileStorage.ts index 18a11c6bd6..e3a395e60d 100644 --- a/src/main/services/FileStorage.ts +++ b/src/main/services/FileStorage.ts @@ -5,7 +5,7 @@ import { getFilesDir, getFileType, getName, - getNotesDir, + getNotesDirAbsolute, getTempDir, readTextFileWithAutoEncoding, scanDir @@ -57,7 +57,7 @@ const DEFAULT_WATCHER_CONFIG: Required = { class FileStorage { private storageDir = getFilesDir() - private notesDir = getNotesDir() + private notesDir = getNotesDirAbsolute() private tempDir = getTempDir() private watcher?: FSWatcher private watcherSender?: Electron.WebContents @@ -774,7 +774,7 @@ class FileStorage { // Get app paths to prevent selection of restricted directories const appDataPath = path.resolve(process.env.APPDATA || path.join(require('os').homedir(), '.config')) const filesDir = path.resolve(getFilesDir()) - const currentNotesDir = path.resolve(getNotesDir()) + const currentNotesDir = getNotesDirAbsolute() // Prevent selecting app data directories if ( diff --git a/src/main/utils/__tests__/file.test.ts b/src/main/utils/__tests__/file.test.ts index d6abefd729..4659321a86 100644 --- a/src/main/utils/__tests__/file.test.ts +++ b/src/main/utils/__tests__/file.test.ts @@ -16,6 +16,8 @@ import { getConfigDir, getFilesDir, getFileType, + getNotesDir, + getNotesDirAbsolute, getTempDir, isPathInside, untildify @@ -245,6 +247,20 @@ describe('file', () => { }) }) + describe('getNotesDir', () => { + it('should return relative path for portability', () => { + const notesDir = getNotesDir() + expect(notesDir).toBe('./Data/Notes') + }) + }) + + describe('getNotesDirAbsolute', () => { + it('should return absolute notes directory path', () => { + const notesDirAbsolute = getNotesDirAbsolute() + expect(notesDirAbsolute).toBe('/mock/userData/Data/Notes') + }) + }) + describe('getAppConfigDir', () => { it('should return correct app config directory path', () => { const appConfigDir = getAppConfigDir('test-app') diff --git a/src/main/utils/file.ts b/src/main/utils/file.ts index f9e44c0134..baec54792a 100644 --- a/src/main/utils/file.ts +++ b/src/main/utils/file.ts @@ -183,7 +183,12 @@ export function getNotesDir() { fs.mkdirSync(notesDir, { recursive: true }) logger.info(`Notes directory created at: ${notesDir}`) } - return notesDir + // Return relative path for better portability across devices + return './Data/Notes' +} + +export function getNotesDirAbsolute() { + return path.join(app.getPath('userData'), 'Data', 'Notes') } export function getConfigDir() {