From a43c3221da3cae7be653f5c00d78639155a57570 Mon Sep 17 00:00:00 2001 From: nicwands Date: Fri, 8 May 2026 13:18:16 -0400 Subject: [PATCH] fix new window loading bug --- out/main/index.js | 2 + src/core/NotesAPI.js | 1 - src/core/index.js | 59 ++++++++++++------------ src/renderer/src/components/NoteRow.vue | 10 +++- src/renderer/src/composables/useNotes.js | 1 + 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/out/main/index.js b/out/main/index.js index dfb83e1..c393b0b 100644 --- a/out/main/index.js +++ b/out/main/index.js @@ -438,6 +438,7 @@ const initializeCore = async (runtime, { plugins }) => { let notesAPI = null; let initPromise = null; const getNotesAPI = async () => { + console.log("getNotesAPI before: ", notesAPI); if (notesAPI) return notesAPI; if (!initPromise) { initPromise = (async () => { @@ -458,6 +459,7 @@ const initializeCore = async (runtime, { plugins }) => { ); notesAPI = new NotesAPI(adapter, encryptionKey); await notesAPI.init(); + console.log("getNotesAPI after: ", notesAPI); return notesAPI; })(); } diff --git a/src/core/NotesAPI.js b/src/core/NotesAPI.js index 2df68b1..947018d 100644 --- a/src/core/NotesAPI.js +++ b/src/core/NotesAPI.js @@ -188,7 +188,6 @@ export default class NotesAPI { getNote(id) { const note = this.notesCache.get(id) - console.log(this.notesCache, id) return note ? { ...note } : null } diff --git a/src/core/index.js b/src/core/index.js index b01775a..116a6c6 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -50,6 +50,35 @@ const initConfigManager = async (runtime, pluginManager) => { return createConfigManager(storage, pluginManager) } +let notesAPI = null +let initPromise = null +const initNotesAPI = async (configManager, pluginManager) => { + // Get fresh config to ensure adapters are populated from main process + const latestConfig = await configManager.loadConfig() + + let encryptionKey = latestConfig?.encryptionKey + + if (!encryptionKey) { + encryptionKey = generateEncryptionKey() + await configManager.setConfig({ + ...latestConfig, + encryptionKey, + }) + } + + const pluginId = latestConfig?.activeAdapter || 'filesystem' + const adapterConfig = latestConfig?.adapters?.[pluginId] || {} + + const adapter = pluginManager.getAdapter(pluginId, adapterConfig) + + const api = new NotesAPI(adapter, encryptionKey) + await api.init() + + notesAPI = api + + return api +} + export const initializeCore = async (runtime, { plugins }) => { const pluginManager = initPluginManager(runtime, plugins) const configManager = await initConfigManager(runtime, pluginManager) @@ -60,39 +89,11 @@ export const initializeCore = async (runtime, { plugins }) => { pluginManager.setActivePlugin(config.activeAdapter, activeConfig) // Create API instance - let notesAPI = null - let initPromise = null const getNotesAPI = async () => { if (notesAPI) return notesAPI if (!initPromise) { - initPromise = (async () => { - // Get fresh config to ensure adapters are populated from main process - const latestConfig = await configManager.loadConfig() - - let encryptionKey = latestConfig?.encryptionKey - - if (!encryptionKey) { - encryptionKey = generateEncryptionKey() - await configManager.setConfig({ - ...latestConfig, - encryptionKey, - }) - } - - const pluginId = latestConfig?.activeAdapter || 'filesystem' - const adapterConfig = latestConfig?.adapters?.[pluginId] || {} - - const adapter = pluginManager.getAdapter( - pluginId, - adapterConfig, - ) - - notesAPI = new NotesAPI(adapter, encryptionKey) - await notesAPI.init() - - return notesAPI - })() + initPromise = initNotesAPI(configManager, pluginManager) } return initPromise diff --git a/src/renderer/src/components/NoteRow.vue b/src/renderer/src/components/NoteRow.vue index a827e98..d8b1afe 100644 --- a/src/renderer/src/components/NoteRow.vue +++ b/src/renderer/src/components/NoteRow.vue @@ -15,11 +15,17 @@ {{ formatDate(note.updatedAt) }}
- -