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>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-12 09:20:09 +00:00
parent cbd4f418f6
commit 6493f1853d
3 changed files with 25 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import {
getFilesDir,
getFileType,
getName,
getNotesDir,
getNotesDirAbsolute,
getTempDir,
readTextFileWithAutoEncoding,
scanDir
@ -57,7 +57,7 @@ const DEFAULT_WATCHER_CONFIG: Required<FileWatcherConfig> = {
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 (

View File

@ -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')

View File

@ -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() {