mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 14:59:27 +08:00
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:
parent
57d9b79e77
commit
bf23c5b209
@ -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)
|
||||
|
||||
@ -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>()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user