diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 43f2065..838c96a 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -105,23 +105,23 @@ function setStatus(message: string) { } } -const store = new Store(STORE_FILENAME) -let storeLoaded = false +let storeInstance: Store | null = null -async function ensureStoreLoaded() { - if (!storeLoaded) { +async function ensureStoreLoaded(): Promise { + if (!storeInstance) { try { - await store.load() + storeInstance = await Store.load(STORE_FILENAME) } catch (error) { console.error("[agent] Falha ao carregar store", error) + throw error } - storeLoaded = true } + return storeInstance } async function loadConfig(): Promise { try { - await ensureStoreLoaded() + const store = await ensureStoreLoaded() const record = await store.get("config") if (!record) return null return record @@ -132,13 +132,13 @@ async function loadConfig(): Promise { } async function saveConfig(config: AgentConfig) { - await ensureStoreLoaded() + const store = await ensureStoreLoaded() await store.set("config", config) await store.save() } async function clearConfig() { - await ensureStoreLoaded() + const store = await ensureStoreLoaded() await store.delete("config") await store.save() }