From 6493f1853db459acf3a3aeea37d4bcb70f8e74d0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 09:20:09 +0000 Subject: [PATCH] refactor: Store default notes path as relative for portability - Changed getNotesDir() to return './Data/Notes' instead of absolute path - Added getNotesDirAbsolute() for cases requiring absolute paths - Updated FileStorage to use getNotesDirAbsolute() - Added tests for both functions This allows the default notes path to be portable across devices while externally selected paths remain absolute. Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com> --- src/main/services/FileStorage.ts | 6 +++--- src/main/utils/__tests__/file.test.ts | 16 ++++++++++++++++ src/main/utils/file.ts | 7 ++++++- 3 files changed, 25 insertions(+), 4 deletions(-) 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() {