From bf23c5b209a317fec657890886ce5fb00a9e3279 Mon Sep 17 00:00:00 2001 From: Pleasure1234 <3196812536@qq.com> Date: Sun, 31 Aug 2025 21:46:39 +0800 Subject: [PATCH] fix: initialize notes path on app startup to resolve missing default directory (#9728) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Update NotesSettings.tsx --------- Co-authored-by: Claude --- .../src/pages/settings/NotesSettings.tsx | 9 ++++++++- src/renderer/src/store/index.ts | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/pages/settings/NotesSettings.tsx b/src/renderer/src/pages/settings/NotesSettings.tsx index ffc1412d5c..0955c93edd 100644 --- a/src/renderer/src/pages/settings/NotesSettings.tsx +++ b/src/renderer/src/pages/settings/NotesSettings.tsx @@ -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(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) diff --git a/src/renderer/src/store/index.ts b/src/renderer/src/store/index.ts index 01bb7d217c..a481026547 100644 --- a/src/renderer/src/store/index.ts +++ b/src/renderer/src/store/index.ts @@ -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 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() export const useAppSelector = useSelector.withTypes() export const useAppStore = useStore.withTypes()