fix: initialize notes path on app startup to resolve missing default directory (#9728)

* fix: initialize notes path on app startup to resolve missing default directory

- Add notes path initialization in store persistStore callback after rehydration
- Update NotesSettings to sync tempPath when notesPath changes from initialization
- Ensure notes directory is set even when user doesn't visit NotesPage first
- Fixes issue where notes path was empty after data reset until NotesPage visit

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Update NotesSettings.tsx

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Pleasure1234 2025-08-31 21:46:39 +08:00 committed by GitHub
parent 57d9b79e77
commit bf23c5b209
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import { initWorkSpace } from '@renderer/services/NotesService'
import { EditorView } from '@renderer/types'
import { Button, Input, message, Switch } from 'antd'
import { FolderOpen } from 'lucide-react'
import { FC, useState } from 'react'
import { FC, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'
@ -29,6 +29,13 @@ const NotesSettings: FC = () => {
const [tempPath, setTempPath] = useState<string>(notesPath || '')
const [isSelecting, setIsSelecting] = useState(false)
// Update tempPath when notesPath changes (e.g., after initialization)
useEffect(() => {
if (notesPath) {
setTempPath(notesPath)
}
}, [notesPath])
const handleSelectWorkDirectory = async () => {
try {
setIsSelecting(true)

View File

@ -19,6 +19,7 @@ import messageBlocksReducer from './messageBlock'
import migrate from './migrate'
import minapps from './minapps'
import newMessagesReducer from './newMessage'
import { setNotesPath } from './note'
import note from './note'
import nutstore from './nutstore'
import ocr from './ocr'
@ -104,7 +105,23 @@ const store = configureStore({
export type RootState = ReturnType<typeof rootReducer>
export type AppDispatch = typeof store.dispatch
export const persistor = persistStore(store)
export const persistor = persistStore(store, undefined, () => {
// Initialize notes path after rehydration if empty
const state = store.getState()
if (!state.note.notesPath) {
// Use setTimeout to ensure this runs after the store is fully initialized
setTimeout(async () => {
try {
const info = await window.api.getAppInfo()
store.dispatch(setNotesPath(info.notesPath))
logger.info('Initialized notes path on startup:', info.notesPath)
} catch (error) {
logger.error('Failed to initialize notes path on startup:', error as Error)
}
}, 0)
}
})
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
export const useAppStore = useStore.withTypes<typeof store>()