fix incorrect config directory by lazily loading electron-store (#23373)

This commit is contained in:
Luke Parker
2026-04-19 13:06:07 +10:00
committed by GitHub
parent 40ba8f3570
commit b34ca44abe
3 changed files with 14 additions and 12 deletions

View File

@@ -4,7 +4,7 @@ import { existsSync, readdirSync, readFileSync } from "node:fs"
import { homedir } from "node:os"
import { join } from "node:path"
import { CHANNEL } from "./constants"
import { getStore, store } from "./store"
import { getStore } from "./store"
const TAURI_MIGRATED_KEY = "tauriMigrated"
@@ -67,7 +67,7 @@ function migrateFile(datPath: string, filename: string) {
}
export function migrate() {
if (store.get(TAURI_MIGRATED_KEY)) {
if (getStore().get(TAURI_MIGRATED_KEY)) {
log.log("tauri migration: already done, skipping")
return
}
@@ -77,7 +77,7 @@ export function migrate() {
if (!existsSync(dir)) {
log.log("tauri migration: no tauri data directory found, nothing to migrate")
store.set(TAURI_MIGRATED_KEY, true)
getStore().set(TAURI_MIGRATED_KEY, true)
return
}
@@ -87,5 +87,5 @@ export function migrate() {
}
log.log("tauri migration: complete")
store.set(TAURI_MIGRATED_KEY, true)
getStore().set(TAURI_MIGRATED_KEY, true)
}

View File

@@ -1,33 +1,33 @@
import { app } from "electron"
import { DEFAULT_SERVER_URL_KEY, WSL_ENABLED_KEY } from "./constants"
import { getUserShell, loadShellEnv } from "./shell-env"
import { store } from "./store"
import { getStore } from "./store"
export type WslConfig = { enabled: boolean }
export type HealthCheck = { wait: Promise<void> }
export function getDefaultServerUrl(): string | null {
const value = store.get(DEFAULT_SERVER_URL_KEY)
const value = getStore().get(DEFAULT_SERVER_URL_KEY)
return typeof value === "string" ? value : null
}
export function setDefaultServerUrl(url: string | null) {
if (url) {
store.set(DEFAULT_SERVER_URL_KEY, url)
getStore().set(DEFAULT_SERVER_URL_KEY, url)
return
}
store.delete(DEFAULT_SERVER_URL_KEY)
getStore().delete(DEFAULT_SERVER_URL_KEY)
}
export function getWslConfig(): WslConfig {
const value = store.get(WSL_ENABLED_KEY)
const value = getStore().get(WSL_ENABLED_KEY)
return { enabled: typeof value === "boolean" ? value : false }
}
export function setWslConfig(config: WslConfig) {
store.set(WSL_ENABLED_KEY, config.enabled)
getStore().set(WSL_ENABLED_KEY, config.enabled)
}
export async function spawnLocalServer(hostname: string, port: number, password: string) {

View File

@@ -4,6 +4,10 @@ import { SETTINGS_STORE } from "./constants"
const cache = new Map<string, Store>()
// We cannot instantiate the electron-store at module load time because
// module import hoisting causes this to run before app.setPath("userData", ...)
// in index.ts has executed, which would result in files being written to the default directory
// (e.g. bad: %APPDATA%\@opencode-ai\desktop-electron\opencode.settings vs good: %APPDATA%\ai.opencode.desktop.dev\opencode.settings).
export function getStore(name = SETTINGS_STORE) {
const cached = cache.get(name)
if (cached) return cached
@@ -11,5 +15,3 @@ export function getStore(name = SETTINGS_STORE) {
cache.set(name, next)
return next
}
export const store = getStore(SETTINGS_STORE)