fix(desktop): ajustar store do agente para build

This commit is contained in:
Esdras Renan 2025-10-08 23:28:08 -03:00
parent 152550a9a0
commit 30928fd938

View file

@ -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<Store> {
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<AgentConfig | null> {
try {
await ensureStoreLoaded()
const store = await ensureStoreLoaded()
const record = await store.get<AgentConfig>("config")
if (!record) return null
return record
@ -132,13 +132,13 @@ async function loadConfig(): Promise<AgentConfig | null> {
}
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()
}