store.ts 831 B

1234567891011121314151617181920212223
  1. import Store from "electron-store"
  2. import electron from "electron"
  3. import { SETTINGS_STORE } from "./store-keys"
  4. const cache = new Map<string, Store>()
  5. // We cannot instantiate the electron-store at module load time because
  6. // module import hoisting causes this to run before app.setPath("userData", ...)
  7. // in index.ts has executed, which would result in files being written to the default directory
  8. // (e.g. bad: %APPDATA%\@opencode-ai\desktop\opencode.settings vs good: %APPDATA%\ai.opencode.desktop.dev\opencode.settings).
  9. export function getStore(name = SETTINGS_STORE) {
  10. const cached = cache.get(name)
  11. if (cached) return cached
  12. const next = new Store({
  13. name,
  14. cwd: electron.app.getPath("userData"),
  15. fileExtension: "",
  16. accessPropertiesByDotNotation: false,
  17. })
  18. cache.set(name, next)
  19. return next
  20. }